KU COSE101 2018기말고사 3번 문제

less than 1 minute read

             
2016 기출 1번 2번 3번 4번 5번  
2017 기출 1번 2번 3번 4번 5번  
2018 기출 1번 2번 3번 4번 5번 6번

복소수는 a+bi의 형태를 가진 수로 ab는 실수이고, ix^2=-1의 해인 허수이다. 복소수 a+bi에서는 a는 real part라고 불리고, b는 imaginary part 라고 불린다. 두 복소수 x=a+bi, y=c+di에 대하여 덧셈 x+y와 곱셈 xy는 다음과 같이 정의 된다.

x+y=(a+c)+(b+d)i

xy=(ac-bd)+(ad+bc)i

복소수를 다음과 같이 구조체로 정의하였다. 복소수의 덧셈과 곱셈을 수행하는 다음 두 함수를 각각 완성하시오.

#include<stdio.h>

struct complex{
	double real;
	double imaginary;
};
typedef struct complex complex;

complex complex_add(complex x, complex y) {
	
}

complex complex_mul(complex x, complex y) {
	
}

int main()
{
	complex x = {1,2}, y = {2,3};
	complex z = complex_mul(complex_add(x,y),y);
	printf("%+lf%+lfi",z.real, z.imaginary);
}

예시 풀이
complex complex_add(complex x, complex y) {
	return {x.real+y.real, x.imaginary+y.imaginary};
}

complex complex_mul(complex x, complex y) {
	return {x.real*y.real-x.imaginary*y.imaginary, x.real*y.imaginary+x.imaginary*y.real};
}

Comments