#include<stdio.h>
void Plus(float a1,float a2,float b1,float b2)
{
float c1,c2;
c1=a1+b1;
c2=a2+b2;
c1=(int)(c1*10)/10.0;
c2=(int)(c2*10)/10.0;
if(a2>0 && b2>0)
{
if(c1==0 && c2==0)
printf(“(%.1f+%.1fi) + (%.1f+%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f+%.1fi) + (%.1f+%.1fi) = %.1fi\n”,a1,a2,b1,b2,a2+b2);
else if(c2==0)
printf(“(%.1f+%.1fi) + (%.1f+%.1fi) = %.1f\n”,a1,a2,b1,b2,a1+b1);
else if(a2+b2<0)
printf(“(%.1f+%.1fi) + (%.1f+%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1+b1,a2+b2);
else
printf(“(%.1f+%.1fi) + (%.1f+%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1+b1,a2+b2);
}
else if(a2>0 && b2<0)
{
if(c1==0 && c2==0)
printf(“(%.1f+%.1fi) + (%.1f%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f+%.1fi) + (%.1f%.1fi) = %.1fi\n”,a1,a2,b1,b2,a2+b2);
else if(c2==0)
printf(“(%.1f+%.1fi) + (%.1f%.1fi) = %.1f\n”,a1,a2,b1,b2,a1+b1);
else if(a2+b2<0)
printf(“(%.1f+%.1fi) + (%.1f%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1+b1,a2+b2);
else
printf(“(%.1f+%.1fi) + (%.1f%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1+b1,a2+b2);
}
else if(a2<0 && b2<0)
{
if(c1==0 && c2==0)
printf(“(%.1f%.1fi) + (%.1f%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f%.1fi) + (%.1f%.1fi) = %.1fi\n”,a1,a2,b1,b2,a2+b2);
else if(c2==0)
printf(“(%.1f%.1fi) + (%.1f%.1fi) = %.1f\n”,a1,a2,b1,b2,a1+b1);
else if(a2+b2<0)
printf(“(%.1f%.1fi) + (%.1f%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1+b1,a2+b2);
else
printf(“(%.1f%.1fi) + (%.1f%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1+b1,a2+b2);
}
else{
if(c1==0 && c2==0)
printf(“(%.1f%.1fi) + (%.1f+%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f%.1fi) + (%.1f+%.1fi) = %.1fi\n”,a1,a2,b1,b2,a2+b2);
else if(c2==0)
printf(“(%.1f%.1fi) + (%.1f+%.1fi) = %.1f\n”,a1,a2,b1,b2,a1+b1);
else if(a2+b2<0)
printf(“(%.1f%.1fi) + (%.1f+%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1+b1,a2+b2);
else
printf(“(%.1f%.1fi) + (%.1f+%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1+b1,a2+b2);
}
return;
}
void Sub(float a1,float a2,float b1,float b2)
{
float c1,c2;
c1=a1-b1;
c2=a2-b2;
c1=(int)(c1*10)/10.0;
c2=(int)(c2*10)/10.0;
if(a2>0 && b2>0)
{
if(c1==0 && c2==0)
printf(“(%.1f+%.1fi) – (%.1f+%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f+%.1fi) – (%.1f+%.1fi) = %.1fi\n”,a1,a2,b1,b2,a2-b2);
else if(c2==0)
printf(“(%.1f+%.1fi) – (%.1f+%.1fi) = %.1f\n”,a1,a2,b1,b2,a1-b1);
else if(a2-b2<0)
printf(“(%.1f+%.1fi) – (%.1f+%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1-b1,a2-b2);
else
printf(“(%.1f+%.1fi) – (%.1f+%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1-b1,a2-b2);
}
else if(a2>0 && b2<0)
{ if(c1==0 && c2==0)
printf(“(%.1f+%.1fi) – (%.1f%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f+%.1fi) – (%.1f%.1fi) = %.1fi\n”,a1,a2,b1,b2,a2-b2);
else if(c2==0)
printf(“(%.1f+%.1fi) – (%.1f%.1fi) = %.1f\n”,a1,a2,b1,b2,a1-b1);
else if(a2-b2<0)
printf(“(%.1f+%.1fi) – (%.1f%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1-b1,a2-b2);
else
printf(“(%.1f+%.1fi) – (%.1f%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1-b1,a2-b2);
}
else if(a2<0 && b2<0)
{ if(c1==0 && c2==0)
printf(“(%.1f%.1fi) – (%.1f%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f%.1fi) – (%.1f%.1fi) = %.1fi\n”,a1,a2,b1,b2,a2-b2);
else if(c2==0)
printf(“(%.1f%.1fi) – (%.1f%.1fi) = %.1f\n”,a1,a2,b1,b2,a1-b1);
else if(a2-b2<0)
printf(“(%.1f%.1fi) – (%.1f%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1-b1,a2-b2);
else
printf(“(%.1f%.1fi) – (%.1f%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1-b1,a2-b2);
}
else
{
if(c1==0 && c2==0)
printf(“(%.1f%.1fi) – (%.1f+%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f%.1fi) – (%.1f+%.1fi) = %.1fi\n”,a1,a2,b1,b2,a2-b2);
else if(c2==0)
printf(“(%.1f%.1fi) – (%.1f+%.1fi) = %.1f\n”,a1,a2,b1,b2,a1-b1);
else if(a2-b2<0)
printf(“(%.1f%.1fi) – (%.1f+%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1-b1,a2-b2);
else
printf(“(%.1f%.1fi) – (%.1f+%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1-b1,a2-b2);
}
return;
}
void Multi(float a1,float a2,float b1,float b2)
{
float c1,c2;
c1=a1*b1-a2*b2;
c2=a1*b2+a2*b1;
c1=(int)(c1*10)/10.0;
c2=(int)(c2*10)/10.0;
if(a2>0 && b2>0)
{
if(c1==0 && c2==0)
printf(“(%.1f+%.1fi) * (%.1f+%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f+%.1fi) * (%.1f+%.1fi) = %.1fi\n”,a1,a2,b1,b2,a1*b2+a2*b1);
else if(c2==0)
printf(“(%.1f+%.1fi) * (%.1f+%.1fi) = %.1f\n”,a1,a2,b1,b2,a1*b1-a2*b2);
else if((a1*b2+a2*b1)<0)
printf(“(%.1f+%.1fi) * (%.1f+%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1*b1-a2*b2,a1*b2+a2*b1);
else
printf(“(%.1f+%.1fi) * (%.1f+%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1*b1-a2*b2,a1*b2+a2*b1);
}
else if(a2>0 && b2<0)
{
if(c1==0 && c2==0)
printf(“(%.1f+%.1fi) * (%.1f%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f+%.1fi) * (%.1f%.1fi) = %.1fi\n”,a1,a2,b1,b2,a1*b2+a2*b1);
else if(c2==0)
printf(“(%.1f+%.1fi) * (%.1f%.1fi) = %.1f\n”,a1,a2,b1,b2,a1*b1-a2*b2);
else if((a1*b2+a2*b1)<0)
printf(“(%.1f+%.1fi) * (%.1f%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1*b1-a2*b2,a1*b2+a2*b1);
else
printf(“(%.1f+%.1fi) * (%.1f%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1*b1-a2*b2,a1*b2+a2*b1);
}
else if(a2<0 && b2<0)
{
if(c1==0 && c2==0)
printf(“(%.1f%.1fi) * (%.1f%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f%.1fi) * (%.1f%.1fi) = %.1fi\n”,a1,a2,b1,b2,a1*b2+a2*b1);
else if(c2==0)
printf(“(%.1f%.1fi) * (%.1f%.1fi) = %.1f\n”,a1,a2,b1,b2,a1*b1-a2*b2);
else if((a1*b2+a2*b1)<0)
printf(“(%.1f%.1fi) * (%.1f%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1*b1-a2*b2,a1*b2+a2*b1);
else
printf(“(%.1f%.1fi) * (%.1f%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1*b1-a2*b2,a1*b2+a2*b1);
}
else
{
if(c1==0 && c2==0)
printf(“(%.1f%.1fi) * (%.1f+%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f%.1fi) * (%.1f+%.1fi) = %.1fi\n”,a1,a2,b1,b2,a1*b2+a2*b1);
else if(c2==0)
printf(“(%.1f%.1fi) * (%.1f+%.1fi) = %.1f\n”,a1,a2,b1,b2,a1*b1-a2*b2);
else if((a1*b2+a2*b1)<0)
printf(“(%.1f%.1fi) * (%.1f+%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,a1*b1-a2*b2,a1*b2+a2*b1);
else
printf(“(%.1f%.1fi) * (%.1f+%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,a1*b1-a2*b2,a1*b2+a2*b1);
}
return;
}
void Div(float a1,float a2,float b1,float b2)
{
float c1,c2;
c1=(a1*b1+a2*b2)/(b1*b1+b2*b2);
c2=(a2*b1-a1*b2)/(b1*b1+b2*b2);
c1=(int)(c1*10)/10.0;
c2=(int)(c2*10)/10.0;
if(a2>0 && b2>0)
{
if(c1==0 && c2==0)
printf(“(%.1f+%.1fi) / (%.1f+%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f+%.1fi) / (%.1f+%.1fi) = %.1fi\n”,a1,a2,b1,b2,(a2*b1-a1*b2)/(b1*b1+b2*b2));
else if(c2==0)
printf(“(%.1f+%.1fi) / (%.1f+%.1fi) = %.1f\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2));
else if((a2*b1-a1*b2) / (b1*b1+b2*b2)<0)
printf(“(%.1f+%.1fi) / (%.1f+%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2),(a2*b1-a1*b2)/(b1*b1+b2*b2));
else
printf(“(%.1f+%.1fi) / (%.1f+%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2),(a2*b1-a1*b2)/(b1*b1+b2*b2));
}
else if(a2>0 && b2<0)
{
if(c1==0 && c2==0)
printf(“(%.1f+%.1fi) / (%.1f%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f+%.1fi) / (%.1f%.1fi) = %.1fi\n”,a1,a2,b1,b2,(a2*b1-a1*b2)/(b1*b1+b2*b2));
else if(c2==0)
printf(“(%.1f+%.1fi) / (%.1f%.1fi) = %.1f\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2));
else if((a2*b1-a1*b2) / (b1*b1+b2*b2)<0)
printf(“(%.1f+%.1fi) / (%.1f%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2),(a2*b1-a1*b2)/(b1*b1+b2*b2));
else
printf(“(%.1f+%.1fi) / (%.1f%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2),(a2*b1-a1*b2)/(b1*b1+b2*b2));
}
else if(a2<0 && b2<0)
{
if(c1==0 && c2==0)
printf(“(%.1f%.1fi) / (%.1f%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f%.1fi) / (%.1f%.1fi) = %.1fi\n”,a1,a2,b1,b2,(a2*b1-a1*b2)/(b1*b1+b2*b2));
else if(c2==0)
printf(“(%.1f%.1fi) / (%.1f%.1fi) = %.1f\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2));
else if((a2*b1-a1*b2) / (b1*b1+b2*b2)<0)
printf(“(%.1f%.1fi) / (%.1f%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2),(a2*b1-a1*b2)/(b1*b1+b2*b2));
else
printf(“(%.1f%.1fi) / (%.1f%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2),(a2*b1-a1*b2)/(b1*b1+b2*b2));
}
else
{
if(c1==0 && c2==0)
printf(“(%.1f%.1fi) / (%.1f+%.1fi) = 0.0\n”,a1,a2,b1,b2);
else if(c1==0)
printf(“(%.1f%.1fi) / (%.1f+%.1fi) = %.1fi\n”,a1,a2,b1,b2,(a2*b1-a1*b2)/(b1*b1+b2*b2));
else if(c2==0)
printf(“(%.1f%.1fi) / (%.1f+%.1fi) = %.1f\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2));
else if((a2*b1-a1*b2) / (b1*b1+b2*b2)<0)
printf(“(%.1f%.1fi) / (%.1f+%.1fi) = %.1f%.1fi\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2),(a2*b1-a1*b2)/(b1*b1+b2*b2));
else
printf(“(%.1f%.1fi) / (%.1f+%.1fi) = %.1f+%.1fi\n”,a1,a2,b1,b2,(a1*b1+a2*b2)/(b1*b1+b2*b2),(a2*b1-a1*b2)/(b1*b1+b2*b2));
}
return;
}
int main()
{
float a1,a2,b1,b2;
scanf(“%f %f %f %f”,&a1,&a2,&b1,&b2);
Plus(a1,a2,b1,b2);
Sub(a1,a2,b1,b2);
Multi(a1,a2,b1,b2);
Div(a1,a2,b1,b2);
return 0;
}
2
6
题主这种错误估计是一个样例没有通过, 可能是一个很特别的case, 一般做这样的
题目, 别写太多代码,!
7
25
输入输出格式
……