#include <stdio.h> #include <stdlib.h> typedef struct{ int shi; int xu; int id; } Xushu,*Xu_shu;
typedef struct{ int length; Xu_shu element; } List;
void shengcheng(List *list,int i,int o,int p){ list->element[i-1].shi=o; list->element[i-1].xu=p; list->element[i-1].id=i; }
Xushu qiuhe(List *list,int a,int b){ Xushu jieguo; jieguo.shi=list->element[a-1].shi+list->element[b-1].shi; jieguo.xu=list->element[a-1].xu+list->element[b-1].xu; jieguo.id=-1; return jieguo; }
Xushu qiucha(List *list,int a,int b){ Xushu jieguo; jieguo.shi=list->element[a-1].shi-list->element[b-1].shi; jieguo.xu=list->element[a-1].xu-list->element[b-1].xu; jieguo.id=-1; return jieguo; }
Xushu qiuji(List *list,int a,int b){ Xushu jieguo; jieguo.shi=list->element[a-1].shi*list->element[b-1].shi-list->element[a-1].xu*list->element[b-1].xu; jieguo.xu=list->element[a-1].shi*list->element[b-1].xu+list->element[a-1].xu*list->element[b-1].shi; jieguo.id=-1; return jieguo; }
int getshi(List *list,int a){ int w; w=list->element[a-1].shi; return w; }
int getxu(List *list,int a){ int w; w=list->element[a-1].xu; return w; }
int main(){ int n,o,p,q,r,s,t; printf("please inuput the length of list of imaginary number: "); scanf("%d",&n); List *list=(List *)malloc(sizeof(List)); list->length=n; list->element=(Xushu *)malloc(sizeof(Xushu)*n); for(int i=1;i<=n;i++){ printf("please input real part and imaginary part of %dst imaginary number ",i); scanf("%d%d",&o,&p); shengcheng(list,i,o,p); } jumpto: printf("The operations:1.addition 2.subtraction 3.multiplication 4.get real part 5.get imaginary part ");
printf("please input the next operation: "); scanf("%d",&q); if(q==1){ printf("please input two ids of imaginary numbers "); scanf("%d%d",&r,&s); printf("the result is %d+(%d)i ",qiuhe(list,r,s).shi,qiuhe(list,r,s).xu); } if(q==2){ printf("please input two ids of imaginary numbers "); scanf("%d%d",&r,&s); printf("the result is %d+(%d)i ",qiucha(list,r,s).shi,qiucha(list,r,s).xu); } if(q==3){ printf("please input two ids of imaginary numbers "); scanf("%d%d",&r,&s); printf("the result is %d+(%d)i ",qiuji(list,r,s).shi,qiuji(list,r,s).xu); } if(q==4){ printf("please input the id of imaginary number "); scanf("%d",&r); printf("the result is %d ",getshi(list,r)); } if(q==5){ printf("please input the id of imaginary number "); scanf("%d",&r); printf("the result is %d ",getxu(list,r)); } printf("whether to continue? please input 1 or 0 "); scanf("%d",&t); if(t==1){ goto jumpto; }
return 0; }