这个代码出不了结果是为什么
#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;
}
编译没错,出不了结果
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- CSDN专家-link 2021-12-19 19:14关注
你的写法都是错的。定义结构指针没有分配空间啊
#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; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记