C_C++
(C언어) 복소수의 사칙연산: 합, 차(빼기), 곱(곱하기), 나누기
고니자니
2023. 3. 21. 16:02
반응형
복소수의 사칙연산
[참고] 복소수의 사칙연산의 계산하는 방법은 다음 사이트를 참고했습니다.
https://www.mathfactory.net/11177
C언어를 이용해서 복소수의 합을 구하는 코드만 작성해 보겠습니다.
복소수 정의는 구조체(struct)를 이용해서 정의합니다.
반응형
#define _CRT_SECURE_NO_WARNINGS // Visual Studio
#include <stdio.h>
struct complex {
double real;
double img;
};
void add_complex(struct complex a, struct complex b)
{
struct complex c;
c.real = a.real + b.real;
c.img = a.img + b.img;
printf("복소수의 합: %g + %gi\n\n", c.real, c.img);
}
int main()
{
struct complex a = { 1.1, 1.0 };
struct complex b = { 2.1, 2.0 };
add_complex(a, b); // 덧셈
return 0;
}
반응형