/*頭一次寫一百五十行的**。也算是迄今寫過最長的**,雖然問題很簡單,但是我還是選擇暴力。*/
7-3 複數四則運算(10 分)
本題要求編寫程式,計算2個複數的和、差、積、商。
輸入在一行中按照a1 b1 a2 b2
的格式給出2個複數c1=a1+b1i
和c2=a2+b2i
的實部和虛部。題目保證c2不為0。
分別在4行中按照(a1+b1i) 運算子 (a2+b2i) = 結果
的格式順序輸出2個複數的和、差、積、商,數字精確到小數點後1位。如果結果的實部或者虛部為0,則不輸出。如果結果為0,則輸出0.0。
2 3.08 -2.04 5.06
(2.0+3.1i) + (-2.0+5.1i) = 8.1i
(2.0+3.1i) - (-2.0+5.1i) = 4.0-2.0i
(2.0+3.1i) * (-2.0+5.1i) = -19.7+3.8i
(2.0+3.1i) / (-2.0+5.1i) = 0.4-0.6i
1 1 -1 -1.01
(1.0+1.0i) + (-1.0-1.0i) = 0.0
(1.0+1.0i) - (-1.0-1.0i) = 2.0+2.0i
(1.0+1.0i) * (-1.0-1.0i) = -2.0i
(1.0+1.0i) / (-1.0-1.0i) = -1.0
#include
#include
#include
int main()
if(fabs(b1-b2)<0.09) printf("(%.1f%.1fi) - (%.1f%.1fi) = %.1f\n",a1,b1,a2,b2,a1-a2);
else if(fabs(a1-a2)<0.09) printf("(%.1f%.1fi) - (%.1f%.1fi) = %.1fi\n",a1,b1,a2,b2,b1-b2);
else
if(a1==0&&b1==0) printf("(%.1f%.1fi) * (%.1f%.1fi) = 0.0\n",a1,b1,a2,b2);
else if((a1*a2-b1*b2)<0.09) printf("(%.1f%.1fi) * (%.1f%.1fi) = %.1fi\n",a1,b1,a2,b2,a1*b2+a2*b1);
else if((a1*b2+a2*b1)<0.09) printf("(%.1f%.1fi) * (%.1f%.1fi) = %.1f\n",a1,b1,a2,b2,a1*a2-b1*b2);
else
if(a1==0&&b1==0) printf("(%.1f%.1fi) / (%.1f%.1fi) = 0.0\n",a1,b1,a2,b2);
else if(fabs((a1*a2+b1*b2)/(a2*a2+b2*b2))<0.09) printf("(%.1f%.1fi) / (%.1f%.1fi) = %.1fi\n",a1,b1,a2,b2,(-a1*b2+a2*b1)/(a2*a2+b2*b2));
else if(fabs((-a1*b2+a2*b1)/(a2*a2+b2*b2))<0.09) printf("(%.1f%.1fi) / (%.1f%.1fi) = %.1f\n",a1,b1,a2,b2,(a1*a2+b1*b2)/(a2*a2+b2*b2));
else
}///後面都是一樣的,就是負數前面的加號刪掉了
else if(b1<0&&b2>0)
if(fabs(b1-b2)<0.09) printf("(%.1f%.1fi) - (%.1f+%.1fi) = %.1f\n",a1,b1,a2,b2,a1-a2);
else if(fabs(a1-a2)<0.09) printf("(%.1f%.1fi) - (%.1f+%.1fi) = %.1fi\n",a1,b1,a2,b2,b1-b2);
else
if(a1==0&&b1==0) printf("(%.1f%.1fi) * (%.1f+%.1fi) = 0.0\n",a1,b1,a2,b2);
else if((a1*a2-b1*b2)<0.09) printf("(%.1f%.1fi) * (%.1f+%.1fi) = %.1fi\n",a1,b1,a2,b2,a1*b2+a2*b1);
else if((a1*b2+a2*b1)<0.09) printf("(%.1f%.1fi) * (%.1f+%.1fi) = %.1f\n",a1,b1,a2,b2,a1*a2-b1*b2);
else
if(a1==0&&b1==0) printf("(%.1f%.1fi) / (%.1f+%.1fi) = 0.0\n",a1,b1,a2,b2);
else if(fabs((a1*a2+b1*b2)/(a2*a2+b2*b2))<0.09) printf("(%.1f%.1fi) / (%.1f+%.1fi) = %.1fi\n",a1,b1,a2,b2,(-a1*b2+a2*b1)/(a2*a2+b2*b2));
else if(fabs((-a1*b2+a2*b1)/(a2*a2+b2*b2))<0.09) printf("(%.1f%.1fi) / (%.1f+%.1fi) = %.1f\n",a1,b1,a2,b2,(a1*a2+b1*b2)/(a2*a2+b2*b2));
else
}else if(b1>0&&b2<0)
if(fabs(b1-b2)<0.09) printf("(%.1f+%.1fi) - (%.1f%.1fi) = %.1f\n",a1,b1,a2,b2,a1-a2);
else if(fabs(a1-a2)<0.09) printf("(%.1f+%.1fi) - (%.1f%.1fi) = %.1fi\n",a1,b1,a2,b2,b1-b2);
else
if(a1==0&&b1==0) printf("(%.1f+%.1fi) * (%.1f%.1fi) = 0.0\n",a1,b1,a2,b2);
else if((a1*a2-b1*b2)<0.09) printf("(%.1f+%.1fi) * (%.1f%.1fi) = %.1fi\n",a1,b1,a2,b2,a1*b2+a2*b1);
else if((a1*b2+a2*b1)<0.09) printf("(%.1f+%.1fi) * (%.1f%.1fi) = %.1f\n",a1,b1,a2,b2,a1*a2-b1*b2);
else
if(a1==0&&b1==0) printf("(%.1f+%.1fi) / (%.1f%.1fi) = 0.0\n",a1,b1,a2,b2);
else if(fabs((a1*a2+b1*b2)/(a2*a2+b2*b2))<0.09) printf("(%.1f+%.1fi) / (%.1f%.1fi) = %.1fi\n",a1,b1,a2,b2,(-a1*b2+a2*b1)/(a2*a2+b2*b2));
else if(fabs((-a1*b2+a2*b1)/(a2*a2+b2*b2))<0.09) printf("(%.1f+%.1fi) / (%.1f%.1fi) = %.1f\n",a1,b1,a2,b2,(a1*a2+b1*b2)/(a2*a2+b2*b2));
else
}else///這才是最初的**。tab,乙個寫著**,敲著**的鬼畜文藝青年。。
if(fabs(b1-b2)<0.09) printf("(%.1f+%.1fi) - (%.1f+%.1fi) = %.1f\n",a1,b1,a2,b2,a1-a2);
else if(fabs(a1-a2)<0.09) printf("(%.1f+%.1fi) - (%.1f+%.1fi) = %.1fi\n",a1,b1,a2,b2,b1-b2);
else
if(a1==0&&b1==0) printf("(%.1f+%.1fi) * (%.1f+%.1fi) = 0.0\n",a1,b1,a2,b2);
else if(fabs(a1*a2-b1*b2)<0.09) printf("(%.1f+%.1fi) * (%.1f+%.1fi) = %.1fi\n",a1,b1,a2,b2,a1*b2+a2*b1);
else if(fabs(a1*b2+a2*b1)<0.09) printf("(%.1f+%.1fi) * (%.1f+%.1fi) = %.1f\n",a1,b1,a2,b2,a1*a2-b1*b2);
else
if(a1==0&&b1==0) printf("(%.1f+%.1fi) / (%.1f+%.1fi) = 0.0\n",a1,b1,a2,b2);
else if(fabs((a1*a2+b1*b2)/(a2*a2+b2*b2))<0.09) printf("(%.1f+%.1fi) / (%.1f+%.1fi) = %.1fi\n",a1,b1,a2,b2,(-a1*b2+a2*b1)/(a2*a2+b2*b2));
else if(fabs((-a1*b2+a2*b1)/(a2*a2+b2*b2))<0.09) printf("(%.1f+%.1fi) / (%.1f+%.1fi) = %.1f\n",a1,b1,a2,b2,(a1*a2+b1*b2)/(a2*a2+b2*b2));
else
}return 0;
}
複數四則運算
include include struct complex void initcomplex complex c,float r1,float r2 void addcomplex complex c,complex c1,complex c2 void subcomplex complex c,...
6 17複數四則運算
設計複數庫,實現基本的複數加減乘除運算。輸入時只需分別鍵入實部和虛部,以空格分割,兩個複數之間用運算子分隔 輸出時按a bi的格式在螢幕上列印結果。參加樣例輸入和樣例輸出。注意考慮特殊情況,無法計算時輸出字串 error 樣例輸入 2 4 3 2 樣例輸出 14 8i 樣例輸入 3 2 1 3 樣例...
複數四則運算 PAT
原題如下 本題要求編寫程式,計算2個複數的和 差 積 商。輸入在一行中按照a1 b1 a2 b2的格式給出2個複數c1 a1 b1i和c2 a2 b2i的實部和虛部。題目保證c2不為0。分別在4行中按照 a1 b1i 運算子 a2 b2i 結果的格式順序輸出2個複數的和 差 積 商,數字精確到小數點...