7-5 复数四则运算 (15 分)

码农问题

#include<stdio.h>
#include<stdlib.h>
typedef struct node{
   
    double a;
    double b;
}fu;
int pan(double a, double b)  //判断实部和虚部是否为零
{
   
    if(a==0&& b!=0)
        return 1;
    else if(a!=0 && b==0)
        return 2;
    else if(a==0 && b==0)
        return 3;
    else if(a!=0 && b!=0)
        return 0;
}
double qu(double a)    //四舍五入函数 只对小数点后两位做
{
   
    double b=(int)(a*10)/10;
    double s=a*100;
    int p=(int)s%10;
    if(abs(p)>=5)
        return a<0?(b-0.1):(b+0.1);
    else if(b==0)
        return 0;
    else if(abs(p)<5 && abs(p)>0)
        return b;
    else if(abs(p)==0)
        return a;
}
int main()
{
   
    double a1, b1, a2, b2;
    fu f[4];
    char ch[4]={
   '+', '-', '*', '/'};
    scanf("%lf%lf%lf%lf", &a1, &b1, &a2, &b2);   //输入
    f[0].a=a1+a2;
    f[0].b=b1+b2;
    f[1].a=a1-a2;
    f[1].b=b1-b2;
    f[2].a=a1*a2-b1*b2;
    f[2].b=a1*b2+a2*b1;
    f[3].a=(a1*a2+b1*b2)/(a2*a2+b2*b2);
    f[3].b=(b1*a2-a1*b2)/(a2*a2+b2*b2);
  // printf("%lf\n", qu(f[3].a));
 /* for(int i=0; i<4; i++) { printf("%.1lf %.1lf\n\n", f[i].a, f[i].b); f[i].a=qu(f[i].a); f[i].b=qu(f[i].b); printf("%.1lf %.1lf\n", f[i].a, f[i].b); }*/
    for(int i=0; i<4; i++)    //判断并输出
    {
   
        if(pan(qu(f[i].a), qu(f[i].b))==1)
            printf("(%.1lf%+.1lfi) %c (%.1lf%+.1lfi) = %.1lfi\n", a1, b1, ch[i], a2, b2, f[i].b);
        else if(pan(qu(f[i].a), qu(f[i].b))==2)
            printf("(%.1lf%+.1lfi) %c (%.1lf%+.1lfi) = %.1lf\n", a1, b1, ch[i], a2, b2, f[i].a);
        else if(pan(qu(f[i].a), qu(f[i].b))==3)
            printf("(%.1lf%+.1lfi) %c (%.1lf%+.1lfi) = 0.0\n", a1, b1, ch[i], a2, b2);
        else if(pan(qu(f[i].a), qu(f[i].b))==0)
            printf("(%.1lf%+.1lfi) %c (%.1lf%+.1lfi) = %.1lf%+.1lfi\n", a1, b1, ch[i], a2, b2, f[i].a, f[i].b);
    }
    return 0;
}