코드를 확인해보세요!
더보기
#include <stdio.h>
struct complex {
double real;
double imag;
}
;
struct complex add(struct complex c1, struct complex c2) {
struct complex result;
result.real = c1.real+c2.real;
result.imag = c1.imag+c2.imag;
return result;
}
struct complex sub(struct complex c1, struct complex c2) {
struct complex result;
result.real = c1.real+c2.real;
result.imag = c1.imag+c2.imag;
return result;
}
struct complex mul(struct complex c1, struct complex c2) {
struct complex result;
result.real = c1.real*c2.real-c1.imag*c2.imag;
result.imag = c1.real*c2.imag+c1.imag*c2.real;
return result;
}
void print(struct complex c) {
printf("%f+%fi\n", c.real,c.imag);
}
int main(void) {
struct complex c1= {
1.0, 2.0
}
;
struct complex c2= {
2.0, 3.0
}
;
struct complex c3;
c3= add(c1, c2);
print(c3);
return 1;
}
더 많은 C언어 글이 궁금하다면?
https://chuinggun.tistory.com/category/C%EC%96%B8%EC%96%B4
댓글