这个代码出不了结果是为什么
#include<stdio.h>
struct complex{
float real;
float imag;
};
struct complex multiply(struct complex x, struct complex y);
struct complex division(struct complex x, struct complex y);
struct complex addition(struct complex x, struct complex y);
struct complex subtraction(struct complex x, struct complex y);
int main()
{
struct complex product[4], x, y;
scanf("%f%f%f%f", &x.real, &x.imag, &y.real, &y.imag);
product[0]= addition(x, y);
product[1]= subtraction(x, y);
product[2]= multiply(x, y);
product[3]= division(x, y);
printf("(%.1f+%.1fi) * (%.1f+%.1fi) = %.1f + %.1fi\n", x.real, x.imag, y.real, y.imag, product[0].real, product[0].imag);
printf("(%.1f+%.1fi) * (%.1f+%.1fi) = %.1f + %.1fi\n", x.real, x.imag, y.real, y.imag, product[1].real, product[1].imag);
printf("(%.1f+%.1fi) * (%.1f+%.1fi) = %.1f + %.1fi\n", x.real, x.imag, y.real, y.imag, product[2].real, product[2].imag);
printf("(%.1f+%.1fi) * (%.1f+%.1fi) = %.1f + %.1fi\n", x.real, x.imag, y.real, y.imag, product[3].real, product[3].imag);
return 0;
}
struct complex addition(struct complex x, struct complex y)
{
struct complex product;
product.real=x.real+y.real;
product.imag=(y.imag+x.imag);
return product;
}
struct complex subtraction(struct complex x, struct complex y)
{
struct complex product;
product->real=x.real-y.real;
product->imag=(x.imag-y.imag);
return product;
}
struct complex multiply(struct complex x, struct complex y)
{
struct complex product;
product->real=x.realy.real-x.imagy.imag;
product->imag=(x.realy.imag+x.imagy.real);
return product;
}
struct complex division(struct complex x, struct complex y)
{
struct complex product;
product->real=(x.realy.real+x.imagy.imag)/(y.realy.real+y.imagy.imag);
product->imag=(x.imagy.real-x.realy.imag)/(y.realy.real+y.imag*y.imag);
return *product;
}
你的写法都是错的。定义结构指针没有分配空间啊
#include<stdio.h>
struct complex{
float real;
float imag;
};
struct complex multiply(struct complex x, struct complex y);
struct complex division(struct complex x, struct complex y);
struct complex addition(struct complex x, struct complex y);
struct complex subtraction(struct complex x, struct complex y);
int main()
{
struct complex product[4], x, y;
scanf("%f%f%f%f", &x.real, &x.imag, &y.real, &y.imag);
product[0]= addition(x, y);
product[1]= subtraction(x, y);
product[2]= multiply(x, y);
product[3]= division(x, y);
printf("(%.1f+%.1fi) + (%.1f+%.1fi) = %.1f + %.1fi\n", x.real, x.imag, y.real, y.imag, product[0].real, product[0].imag);
printf("(%.1f+%.1fi) - (%.1f+%.1fi) = %.1f + %.1fi\n", x.real, x.imag, y.real, y.imag, product[1].real, product[1].imag);
printf("(%.1f+%.1fi) * (%.1f+%.1fi) = %.1f + %.1fi\n", x.real, x.imag, y.real, y.imag, product[2].real, product[2].imag);
printf("(%.1f+%.1fi) / (%.1f+%.1fi) = %.1f + %.1fi\n", x.real, x.imag, y.real, y.imag, product[3].real, product[3].imag);
return 0;
}
struct complex addition(struct complex x, struct complex y)
{
struct complex product;
product.real=x.real+y.real;
product.imag=(y.imag+x.imag);
return product;
}
struct complex subtraction(struct complex x, struct complex y)
{
struct complex product;
product.real=x.real-y.real;
product.imag=(x.imag-y.imag);
return product;
}
struct complex multiply(struct complex x, struct complex y)
{
struct complex product;
product.real=x.real*y.real-x.imag*y.imag;
product.imag=(x.real*y.imag+x.imag*y.real);
return product;
}
struct complex division(struct complex x, struct complex y)
{
struct complex product;
product.real=(x.real*y.real+x.imag*y.imag)/(y.real*y.real+y.imag*y.imag);
product.imag=(x.imag*y.real-x.real*y.imag)/(y.real*y.real+y.imag*y.imag);
return product;
}