#include "stdio.h"
struct complex{
float a;//实部
float b;//虚部
};
complex addcomplex(complex a,complex b)
{
complex c;
c.a=a.a+b.a;
c.b=a.b+b.b;
return c;
}
complex subcomplex(complex a,complex b)
{
complex c;
c.a=a.a-b.a;
c.b=a.b-b.b;
return c;
}
complex mulcomplex(complex a,complex b)
{
complex c;
c.b=a.a*b.b+a.b*b.a;
c.a=a.a*b.a-a.b*b.b;
return c;
}
main()
{
complex a,b,c;
printf("\n分别输入复数a的实部和虚部:");
scanf("%f %f",&a.a,&a.b);
printf(\n分别输入复数b的实部和虚部:");
scanf("%f %f",&b.a,&b.b);
c=addcomplex(a,b);
printf("\n复数a:%di+%d加上复数b:%di+%d等于%di+%d",a.b,a.a,b.b,b.a,c.b,c.a);
c=subcomplex(a,b);
printf("\n复数a:%di+%d减去复数b:%di+%d等于%di+%d",a.b,a.a,b.b,b.a,c.b,c.a);
c=mulcomplex(a,b);
printf("\n复数a:%di+%d乘上复数b:%di+%d等于%di+%d",a.b,a.a,b.b,b.a,c.b,c.a);
}
用类比较好