当前位置:网站首页>7-5 复数四则运算
7-5 复数四则运算
2022-06-12 11:35:00 【漠–】
题目
7-5 复数四则运算
分数 25
作者 乔林
单位 清华大学
本题要求编写程序,计算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。
输入样例1:
2 3.08 -2.04 5.06
输出样例1:
(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
输入样例2:
1 1 -1 -1.01
输出样例2:
(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<stdio.h>
double re(double e){
if(e>=0){
e=(double)(int)(e*10+0.5)/10;
}else{
e=(double)(int)(e*10-0.5)/10;
}
return e;
}
void Print(double a,double b,double c,double d,double e,double f,char g)
{
if(e!=0&&f!=0){
printf("(%.1lf%+.1lfi) %c (%.1lf%+.1lfi) = %.1lf%+.1lfi\n",a,b,g,c,d,
e,f);
}else if(e==0&&f==0){
printf("(%.1lf%+.1lfi) %c (%.1lf%+.1lfi) = 0.0\n",a,b,g,c,d);
}else if(e==0){
printf("(%.1lf%+.1lfi) %c (%.1lf%+.1lfi) = %.1lfi\n",a,b,g,c,d,f);
}else{
printf("(%.1lf%+.1lfi) %c (%.1lf%+.1lfi) = %.1lf\n",a,b,g,c,d,e);
}
}
int main()
{
double a,b,c,d,e,f;
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
e=a+c;
f=b+d;
e=re(e);
f=re(f);
Print(a,b,c,d,e,f,'+');
e=a-c;
f=b-d;
e=re(e);
f=re(f);
Print(a,b,c,d,e,f,'-');
e=(a*c-b*d);
f=(b*c+a*d);
e=re(e);
f=re(f);
Print(a,b,c,d,e,f,'*');
e=(a*c+b*d)/(c*c+d*d);
f=(b*c-a*d)/(c*c+d*d);
e=re(e);
f=re(f);
Print(a,b,c,d,e,f,'/');
}
边栏推荐
- Summary of rosbridge use cases_ Chapter 26 opening multiple rosbridge service listening ports on the same server
- 6.6 separate convolution
- 890. find and replace mode
- rosbridge使用案例心得总结之_第26篇在同一个服务器上打开多个rosbridge服务监听端口
- Construction and construction of meta Universe System
- AcWing 1921. 重新排列奶牛(环图)
- Socket programming UDP
- Drqueueonrails integrated LDAP authentication
- DS18B20 digital thermometer (I) electrical characteristics, power supply and wiring mode
- MySQL锁查漏补缺
猜你喜欢

conda环境下pip install 无法安装到指定conda环境中(conda环境的默认pip安装位置)

人類想要擁有金錢、權力、美麗、永生、幸福……但海龜只想做一只海龜

Socket Programming TCP

Relatively rare exception records in UI automation test

6.6 Convolution de séparation

^34 scope interview questions

ReentrantLock源码分析

SOT23(Small Outline Transistor)

十折交叉验证代码中的问题

K52. Chapter 1: installing kubernetes v1.22 based on kubeadm -- cluster deployment
随机推荐
go基于阿里云实现发送短信
Index in MySQL show index from XXX the meaning of each parameter
AcWing 1912. 里程表(枚举)
Clickhouse column basic data type description
Redis summary
Reentrantlock source code analysis
scanf返回值被忽略的原因及其解决方法
arm交叉编译链下载地址
十折交叉验证代码中的问题
AcWing 1995. 见面与问候(模拟)
go基于腾讯云实现发送短信
C# 36. DataGridView line number
人類想要擁有金錢、權力、美麗、永生、幸福……但海龜只想做一只海龜
Summary of rosbridge use cases_ Chapter 26 opening multiple rosbridge service listening ports on the same server
Lambda表达式 | 浅解
MySQL45讲 01 | 基础架构:一条SQL查询语句是如何执行的?
C# 37. textbox滚动条与多行
AcWing 1986. 镜子(模拟,环图)
UML series articles (30) architecture modeling -- product diagram
Construction and construction of meta Universe System