반응형
구조체를 이용하여 복소수를 다음과 같이 정의하고 복소수의 덧셈을 수행하는 함수를 작성하고 테스트하라.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> struct complex{ double real; double imag; }; struct complex complex_add(struct complex c1, struct complex c2); int main(void) { struct complex a,b,res; a.real=0;a.imag=0;b.real=0;b.imag=0; printf("복소수 a의 실수부와 허수부를 차례로 입력하세요.\n"); scanf("%lf %lf", &a.real, &a.imag); printf("복소수 b의 실수부와 허수부를 차례로 입력하세요.\n"); scanf("%lf %lf", &b.real, &b.imag); res=complex_add(a,b); printf("결과는 %lf+(%lf)j 입니다.\n",res.real, res.imag); return 0; } struct complex complex_add(struct complex c1, struct complex c2) { struct complex sum; sum.real=c1.real+c2.real; sum.imag=c1.imag+c2.imag; return sum; } | cs |
반응형
'컴퓨터 & 프로그래밍 & 전자공학 > C언어' 카테고리의 다른 글
이메일 구조체 (0) | 2016.12.27 |
---|---|
벡터 합 (0) | 2016.12.27 |
사각형 판별과 둘레와 넓이 (0) | 2016.12.27 |
포인터 평면 위의 점 (0) | 2016.12.27 |
좌표 일치 확인 (0) | 2016.12.27 |