当前位置:网站首页>复数四则运算(二十三行简洁代码)
复数四则运算(二十三行简洁代码)
2022-06-21 07:47:00 【Crer_lu】
本题要求编写程序,计算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>
#include<math.h>
#define ins 0.05
void print(double a, double b){
if(fabs(a) < ins && fabs(b) < ins) printf("0.0\n");
else if(fabs(a) < ins && fabs(b) >= ins) printf("%.1fi\n", b);
else if(fabs(a) >= ins && fabs(b) < ins) printf("%.1f\n", a);
else printf("%.1lf%+.1lfi\n", a, b);
}
int main(){
double a, b, c, d;
scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
printf("(%.1f%+.1fi) + (%.1f%+.1fi) = ", a, b, c, d);
print(a + c, b + d);
printf("(%.1f%+.1fi) - (%.1f%+.1fi) = ", a, b, c, d);
print(a - c, b - d);
printf("(%.1f%+.1fi) * (%.1f%+.1fi) = ", a, b, c, d);
print(a * c - b * d, a * d + b * c);
printf("(%.1f%+.1fi) / (%.1f%+.1fi) = ", a, b, c, d);
print((a * c + b * d) / (c * c + d * d), (b * c - a * d) / (c * c + d * d));
return 0;
}
边栏推荐
- Sword finger offer (2nd Edition) brush questions | 04 Find in 2D array
- RDKit | 合成可行性分数--SA SCORE
- 2021-07-28 STM32F103 configuration information
- Leetcode topic [array] -40- combined sum II
- Is the index of nine interview sites of ten companies invalid?
- 2021-06-16 STM32F103 exti interrupt identification using firmware library
- Random random number class
- A table to easily understand the prefix and suffix of increment and decrement operators
- Research Report on anhydrous trisodium phosphate industry - market status analysis and development prospect forecast
- mysql分页查询如何优化
猜你喜欢

dried food! Neuron competitive initialization strategy based on information bottleneck theory

2021-07-28 STM32F103 I2C Hardware Transfer Include previous IO Clock EXIT USB use firmware library

Learning Tai Chi maker esp8226 (IX) JSON data communication III

Parameter estimation -- a general problem of parameter estimation

JVM内存模型概念

arduino有关软件卸载,库的卸载问题

2021-07-28 STM32F103配置信息

Rdkit | molecular similarity based on molecular fingerprint

升级Jenkins步骤和遇到的问题

Ansa secondary development - external programs use socket to communicate with ansa
随机推荐
What are the differences between SQL and MySQL
[visualization - source code reading] antvis / g-base interpretation - 1
为什么智慧城市需要数字孪生?
卧槽,一行代码就可将网页直接转pdf保存下来(pdfkit)
25 parameter estimation - Determination of sample size
为什呢代码没报错但是数据库里边的数据显示不出来
How to view the MySQL installation path
PostgreSQL数据库头胎——后台一等公民进程StartupDataBase StartupXLOG函数进入Recovery模式
MATLAB快速入门
RDKIT | 基于分子指纹的分子相似性
What is a multi domain SSL certificate?
Yyds dry goods inventory rapid establishment of CEPH cluster
A shell script to realize automatic expiration of Prometheus push gateway indicators
What is the MySQL database zipper table
Ansa secondary development - external programs use socket to communicate with ansa
[UML modeling] (4) sequence diagram of UML modeling
QML control type: drawer
QML控件类型:Drawer
2021 - 06 - 16 stm32f103 exti interruption identification using firmware Library
Mingming has just changed his profession and won five offers as soon as he graduated