当前位置:网站首页>7-5 complex quaternion operation
7-5 complex quaternion operation
2022-06-12 11:57:00 【Desert –】
subject
7-5 Four operations of complex number
fraction 25
author Jolin
Company Tsinghua University
This question requires the preparation of procedures , Calculation 2 The sum of two plurals 、 Bad 、 product 、 merchant .
Input format :
Type in a line and press a1 b1 a2 b2 The format of 2 Plural C1=a1+b1i and C2=a2+b2i The real part and the virtual part of . Title assurance C2 Not for 0.
Output format :
Respectively in 4 In line with (a1+b1i) Operator (a2+b2i) = The format of the results is output sequentially 2 The sum of two plurals 、 Bad 、 product 、 merchant , The number is accurate to the decimal point 1 position . If the real or imaginary part of the result is 0, No output . If the result is 0, The output 0.0.
sample input 1:
2 3.08 -2.04 5.06
sample output 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
sample input 2:
1 1 -1 -1.01
sample output 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
Ideas
Multiplication and division formula of complex number 
Code
#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,'/');
}
边栏推荐
- Unlimited growth, we will all go to the future | the 15th anniversary of the founding of InfoQ China
- Design of secure chat tool based on C #
- Design of virtual scrolling list
- Batch load/store instructions of arm instruction set
- Video JS library uses custom components
- Lambda and filter, index of list and numpy array, as well as various distance metrics, concatenated array and distinction between axis=0 and axis=1
- Basic concepts of machine learning
- QML学习 第二天
- kubernetes集群搭建
- LeetCode_二分搜索_中等_162. 寻找峰值
猜你喜欢

Ficusjs series (I) introduction to ficusjs

Design of secure chat tool based on C #

LeetCode 1037. Effective boomerang (vector cross product)

The second day of QML study

Basic principle of Doppler effect

UML系列文章(31)体系结构建模---部署图

LeetCode 890. Find and replace mode (analog + double hash table)

Socket implements TCP communication flow

Reentrantlock source code analysis

Lambda and filter, List 和 numpy array的索引,以及各种距离指标distance-metrics,拼接数组以及axis=0 and axis=1的区分
随机推荐
5g NR protocol learning -- ts38.211 downlink channel
Why is there no traffic after the launch of new products? How should new products be released?
[foundation of deep learning] back propagation method (1)
Cookie和Session
Inter class and intra class relations in video classification -- regularization
Face recognition PIP failed to install Dlib Library
QML学习 第一天
Spark common encapsulation classes
UML系列文章(30)体系结构建模---制品图
LeetCode_二分搜索_中等_162. 寻找峰值
Relation entre les classes et à l'intérieur des classes de classification vidéo - - Régularisation
ARM指令集之Load/Store访存指令(一)
TinyMCE series (III) introduction to common TinyMCE APIs
Unit test case framework --unittest
Judge whether the network file exists, obtain the network file size, creation time and modification time
JS to load and display Excel files
Shardingjdbc-5.1.0 monthly horizontal table splitting + read-write separation, automatic table creation and node table refresh
如何确定首页和搜索之间的关系呢?首页与搜索的关系
The second day of QML study
Manuscript manuscript format preparation