设计一个关于复数的结构类型,并实现复数的四则运算

学习 时间:2026-04-04 20:46:53 阅读:9508
设计一个关于复数的结构类型,并实现复数的四则运算C语言

最佳回答

直率的御姐

故意的紫菜

2026-04-04 20:46:53

#include
struct fushu
{
int x,y;
};
void count(struct fushu *m,struct fushu *n);
void main()
{
struct fushu m,n;
printf("Please input the first num:\n");
scanf("%d%di",&m。x,&m。y);
printf("Please input the second num:\n");
scanf("%d%di",&n。x,&n。y);
count(&m,&n);
}
void count(struct fushu *m,struct fushu *n)
{
int fuhao;
printf("input the sign 1:+,2:-,3:*,4:/");
scanf("%d",&fuhao);
switch (fuhao){
case 1:
{
if((m->y+n->y)>=0)
printf("%d+%di",(m->x+n->x),(m->y+n->y));
else
printf("%d%di",(m->x+n->x),(m->y+n->y));
}
break;
case 2:
if((m->y+n->y)>=0)
printf("%d+%di",(m->x-n->x),(m->y-n->y));
else
printf("%d%di",(m->x-n->x),(m->y-n->y));
break;
case 3:
if((m->y+n->y)x*n->x),(m->y*n->y));
else
printf("%d%di",(m->x*n->x),(m->y*n->y));
break;
case 4:
if((m->y+n->y)x/n->x),(m->y/n->y));
else
printf("%d%di",(m->x/n->x),(m->y/n->y));
break;
default:
printf("Error sign");
}
}

最新回答共有2条回答

  • 高贵的冥王星
    回复
    2026-04-04 20:46:53

    #includestruct fushu{int x,y;};void count(struct fushu *m,struct fushu *n);void main(){struct fushu m,n;printf("Please input the first num:\n");scanf("%d%di",&m。x,&m。y);printf("Please input the second num:\n");scanf("%d%di",&n。x,&n。y);count(&m,&n);}void count(struct fushu *m,struct fushu *n){int fuhao;printf("input the sign 1:+,2:-,3:*,4:/");scanf("%d",&fuhao);switch (fuhao){case 1:{if((m->y+n->y)>=0)printf("%d+%di",(m->x+n->x),(m->y+n->y));elseprintf("%d%di",(m->x+n->x),(m->y+n->y));}break;case 2:if((m->y+n->y)>=0)printf("%d+%di",(m->x-n->x),(m->y-n->y));elseprintf("%d%di",(m->x-n->x),(m->y-n->y));break;case 3:if((m->y+n->y)x*n->x),(m->y*n->y));elseprintf("%d%di",(m->x*n->x),(m->y*n->y));break;case 4:if((m->y+n->y)x/n->x),(m->y/n->y));elseprintf("%d%di",(m->x/n->x),(m->y/n->y));break;default:printf("Error sign");}}

上一篇 林子大了什么鸟都有怎么翻译

下一篇 水上飞机种类有哪些