#include<stdio.h>
#include<stdlib.h>
struct complex {
float real;
float imag;
};
void creator_ca(complex *P){
//A=(float*)malloc(sizeof(float));
//printf("please put in two terger to real and imag");
scanf("%f%f",&P->real,&P->imag);
}
void creator_cb(complex *Q){
//B=(float*)malloc(sizeof(float));
//printf("please put in two terger to real and imag");
scanf("%f%f",&Q->real,&Q->imag);
}
void putout_ca(complex *P){
if(P->imag==0)
printf("the A=%f",P->real);printf("/n");
if(P->real==0&&(P->imag)!=0)
printf("the A=%fi",P->imag);printf("/n");
if(P->imag>0)
printf("the A=%f+%fi",P->real,P->imag);printf("/n");
if(P->imag<0)
printf("the A=%f%fi",P->real,P->imag);printf("/n");
}
void putout_cb(complex *Q){
if(Q->imag==0)
printf("the B=%f",Q->real);printf("/n");
if(Q->real==0&&(Q->imag)!=0)
printf("the B=%fi",Q->imag);printf("/n");
if(Q->imag>0)
printf("the B=%f+%fi",Q->real,Q->imag);printf("/n");
if(Q->imag<0)
printf("the B=%f%fi",Q->real,Q->imag);printf("/n");
}
void Addcomplex(complex *P,complex *Q){
struct complex sum;
sum.real =P->real+Q->real;
sum.imag =P->imag+Q->imag;
if(sum.imag==0)
printf("the A+B=%f",sum.real);printf("/n");
if(sum.real==0&&(sum.imag)!=0)
printf("the A+B=%fi",sum.imag);printf("/n");
if((sum.real) !=0&&sum.imag>0)
printf("the A+B=%f+%fi",sum.real,sum.imag);printf("/n");
/*if((sum.real)==0&&sum.imag>0)
printf("the A+B=%fi",sum.imag);printf("/n");*/
if((sum.real) !=0&&sum.imag<0)
printf("the A+B=%f%fi",P->real,P->imag);printf("/n");
/*if((P->real)==0&&P->imag<0)
printf("the A+B=%fi",P->imag);printf("/n");*/
}
void minuscomplex(complex *P,complex *Q){
struct complex cha;
cha.real =P->real-Q->real;
cha.imag =P->imag-Q->imag;
if(cha.imag==0){
//printf("1");用来判断那一个if语句执行
printf("the A-B=%f",cha.real);printf("/n");}
if(cha.real==0&&(cha.imag)!=0){
//printf("2");
printf("the A-B=%fi",cha.imag);printf("/n");}
if((cha.real)!=0&&cha.imag>0){
//printf("3");
printf("the A-B=%f+%fi",cha.real,cha.imag);printf("/n");}
/*if((P->real)==0&&P->imag>0){
//printf("4");
printf("the A-B=%fi",P->imag);printf("/n");}*/
if((cha.real)!=0&&cha.imag<0){
//printf("5");
printf("the A-B=%f%fi",cha.real,cha.imag);printf("/n");}
/*if((P->real)==0&&P->imag<0){printf("6");//不慎重复的判断
printf("the A-B=%fi",P->imag);printf("/n");}*/
//printf("%f,%f/n",P->real ,P->imag );
// printf("%f,%f/n",Q->real ,Q->imag );//检验A,B中值是否发生改变
}
void Jicomplex(complex *P,complex *Q){
struct complex JI;
JI.real =(P->real*Q->real)-(P->imag*Q->imag);
JI.imag =(P->real*Q->imag)+(P->imag*Q->real);
if(JI.imag==0){printf("1");
printf("the A*B=%f",JI.real);printf("/n");}
if(JI.real==0&&(JI.imag)!=0){printf("2");
printf("the A*B=%fi",JI.imag);printf("/n");}
if((JI.real) !=0&&JI.imag>0){printf("3");
printf("the A*B=%f+%fi",JI.real,JI.imag);printf("/n");}
/*if((A->real)==0&&A->imag>0){printf("4");
printf("the A*B=%fi",P->imag);printf("/n");}*/
if((JI.real) !=0&&JI.imag<0){printf("5");
printf("the A*B=%f%fi",JI.real,JI.imag);printf("/n");}
/*if((JI.real)==0&&JI.imag<0){printf("6");
printf("the A*B=%fi",JI.imag);printf("/n");}*/
}
void main(){
struct complex A,B;
struct complex *P=&A,*Q=&B;
printf("you should creator two complex A and B/n");
printf("please put in A's real and imag/n");
creator_ca(P);
printf("please put in B's real and imag:/n");
creator_cb(Q);
putout_ca(P);
putout_cb(Q);
Addcomplex(P,Q);
minuscomplex(P,Q);
Jicomplex(P,Q);
}