结构体作为形参的简单程序,关于复数的计算,函数哪里有问题?
#include<stdio.h>struct mycomplex
{
double real;
double image;
};
struct mycomplex input(void)
struct mycomplex add(struct mycomplex c1,struct mycomplex c2)
struct mycomplex mul(struct mycomplex c1,struct mycomplex c2)
void output(struct mycomplex c1)
int main(void)
{
struct mycomplex a,b,c,d;
a=input();
b=input();
c=add(a,b);
d=mul(a,b);
output(c);
output(d);
return 0;
}
struct mycomplex input(void)
{
struct mycomplex c1;
scanf("%lf",&c1.real);
scanf("%lf",&c1.image);
return c1;
}
struct mycomplex add(struct mycomplex c1,struct mycomplex c2)
{
mycomplex c;
c.real=c1.real+c2.real;
c.image=c1.image+c2.image;
return c;
}
struct mycomplex mul(struct mycomplex c1,struct mycomplex c2)
{
mycomplex d;
d.real=(c1.real*b.real)+(c2.image*a.image);
d.image=(c1.real*b.image)+(c2.image*b.real);
return d;
}
void output(struct mycomplex c1)
{
printf("%lf+%lf*i",c1.real,c1.image);
}