PAT 乙级 (Basic Level) Practice (中文)1051
2019-03-01 16:57
253 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/arthur01p/article/details/88063201
1051 复数乘法 (15 分)
复数可以写成 (A+Bi)(A+Bi)(A+Bi) 的常规形式,其中 AAA 是实部,BBB 是虚部,iii 是虚数单位,满足 i2=−1i^2^=−1i2=−1;也可以写成极坐标下的指数形式 (R×e(Pi))(R×e^(Pi)^)(R×e(Pi)),其中 R 是复数模,P 是辐角,i 是虚数单位,其等价于三角形式 (R(cos(P)+isin(P))(R(cos(P)+isin(P))(R(cos(P)+isin(P))。
现给定两个复数的 RRR 和 PPP,要求输出两数乘积的常规形式。
输入格式:
输入在一行中依次给出两个复数的 R1R1R1,P1P1P1, R2R2R2, P2P2P2,数字间以空格分隔。
输出格式:
在一行中按照 A+BiA+BiA+Bi 的格式输出两数乘积的常规形式,实部和虚部均保留 2 位小数。注意:如果 B 是负数,则应该写成 A−BiA-BiA−Bi 的形式。
输入样例:
2.3 3.5 5.2 0.4
输出样例:
-8.68-8.23i
代码
/*先把两个三角形式的极坐标相乘,再将其转化称常规形式*/ #include <cstdio> #include <cmath> int main () { double R1, P1, R2, P2; double R, P, a, b; scanf ("%lf %lf %lf %lf", &R1, &P1, &R2, &P2); R = R1 * R2; P = P1 + P2; a = R * cos(P); b = R * sin(P); if (a >= -0.005 && a < 0) { printf ("0.00"); } else { printf ("%.2f", a); } if (b >= 0) { printf ("+%.2fi", b); }else if (b >= -0.005 && b < 0) { printf ("+0.00i"); } else { printf ("-%.2fi", fabs(b)); } return 0; }
相关文章推荐
- PAT 乙级 (Basic Level) Practice (中文)1055
- PAT 乙级 (Basic Level) Practice (中文)1056
- PAT 乙级 (Basic Level) Practice (中文)1057
- PAT 乙级 (Basic Level) Practice (中文)1058
- PAT 乙级 (Basic Level) Practice (中文)1059
- PAT 乙级 (Basic Level) Practice (中文)1060
- PAT 乙级 (Basic Level) Practice (中文)1052
- PAT 乙级 (Basic Level) Practice (中文)1061
- PAT 乙级 (Basic Level) Practice (中文)1053
- PAT 乙级 (Basic Level) Practice (中文)1054
- PAT (Basic Level) Practice(中文)[目录]
- PAT (Basic Level) Practice (中文)1086 就不告诉你(C语言)
- PAT (Basic Level) Practice (中文)1006 换个格式输出整数
- PAT (Basic Level) Practice (中文)1002 写出这个数 (20 分)
- PAT (Basic Level) Practise (中文)1051. 复数乘法 (15)
- PAT乙级真题及训练集 PAT (Basic Level) Practise (中文)1003. 我要通过!
- PAT (Basic Level) Practice (中文)1080 MOOC期终成绩(C语言)
- PAT (Basic Level) Practice (中文)1087 有多少不同的值(C语言)
- PAT (Basic Level) Practice (中文)1008 数组元素循环右移问题
- PAT (Basic Level) Practice (中文)1063 计算谱半径(C语言)