반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
how to compile | |
C99 표준 | |
hacker@rust:~/clang$ gcc -o c1 c1.c | |
hacker@rust:~/clang$ ./c1 | |
c1: 2.0 + 3.0i | |
c2: 4.0 + -2.0i | |
Sum: 6.0 + 1.0i | |
Difference: -2.0 + 5.0i | |
Product: 14.0 + 8.0i | |
Division: 0.1 + 0.8i | |
*/ | |
#include <stdio.h> | |
#include <complex.h> | |
int main() { | |
// 복소수 생성 | |
double complex c1 = 2.0 + 3.0 * I; | |
double complex c2 = 4.0 - 2.0 * I; | |
// 복소수 사칙연산 | |
double complex sum = c1 + c2; | |
double complex difference = c1 - c2; | |
double complex product = c1 * c2; | |
double complex division = c1 / c2; | |
// 복소수 출력 | |
printf("c1: %.1f + %.1fi\n", creal(c1), cimag(c1)); | |
printf("c2: %.1f + %.1fi\n", creal(c2), cimag(c2)); | |
printf("Sum: %.1f + %.1fi\n", creal(sum), cimag(sum)); | |
printf("Difference: %.1f + %.1fi\n", creal(difference), cimag(difference)); | |
printf("Product: %.1f + %.1fi\n", creal(product), cimag(product)); | |
printf("Division: %.1f + %.1fi\n", creal(division), cimag(division)); | |
return 0; | |
} |
반응형