复数四则运算

#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);

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值