複數加法1
user_3763047219
c_cpp
3 years ago
725 B
6
Indexable
// 2+3i real imag
struct complex {
int real;
int imag;
};
//結構型態的宣告 傳進兩個結構 回傳一個結構
struct complex add_complex(struct complex a, struct complex b)
{
struct complex c;
c.real = a.real + b.real;
c.imag = a.imag + b.imag;
return c;
}
void print_complex(struct complex c)
{
printf("%d +%di\n", c.real, c.imag);
}
//struct complex mul_complex(struct complex a, struct complex b)
//{
//struct complex c;
//c.real = a.real*b.imag+a.imag*b.real-a.real*b.real;
//c.imag = a.imag * b.imag;
//return c;
//}
int main()
{
struct complex a = { 1,3 }, b = { 5, 2 }, c;
//c = a + b;
c = add_complex(a, b);
//print_complex(c);
//c = a * b;
}Editor is loading...