题目描述
我们可以用下列结构描述复数信息
struct complex
{
int real;
int image;
};
试写出两个通用函数,分别用来求两复数的和与积。其函数原型分别为:
struct complex add(struct complex c1,struct complex c2);
即参数和返回值用结构变量。
输入
输入数据有若干行。每行上有四个整数,前两个表示一个复数的实部和虚部,后两个表示另一个复数的实部和虚部。
输出
对于每一组数据,输出两复数的和与积,格式参照样例输出。
样例输入
1 2 3 4
2 1 4 -1
样例输出
4+(6i)
-5+(10i)
6+(0i)
9+(2i)
#include<stdio.h>
struct complex add(struct complex c1,struct complex c2);
struct complex amass(struct complex c1,struct complex c2);
struct complex
{
int real;
int image;
};
void main()
{
struct complex a,b;
while(scanf("%d%d%d%d",&a.real,&a.image,&b.real,&b.image)!=EOF)
{
add(a,b);
amass(a,b);
}
}
struct complex add(struct complex c1,struct complex c2)
{
printf("%d+(%di)\n",c1.real+c2.real,c1.image+c2.image);
return c1;
}
struct complex amass(struct complex c1,struct complex c2)
{
printf("%d+(%di)\n",(c1.real*c2.real-c1.image*c2.image),(c1.real*c2.image+c2.real*c1.image));
return c1;
}