5-36 複數四則運算 (15分)
#include<iostream> #include<cstdio> #include<iomanip> #include<cmath> using namespace std; int main() { double a1,i1,a2,i2; cin>>a1>>i1>>a2>>i2; double jiashi,jiaxu; double jianshi,jianxu; double chengshi,chengxu; double chushi,chuxu; jiashi=a1+a2; jiaxu=i1+i2; jianshi=a1-a2; jianxu=i1-i2; chengshi=a1*a2-i1*i2; chengxu=a2*i1+a1*i2; chushi=(a1*a2+i1*i2)/(a2*a2+i2*i2); chuxu=(i1*a2-a1*i2)/(a2*a2+i2*i2); cout<<fixed<<setprecision(1)<<"("<<a1; if(i1>=0){ cout<<"+"; } cout<<i1<<"i"<<") + ("<<a2; if(i2>=0){ cout<<"+"; } cout<<i2<<"i) = "; if(abs(jiashi)>=0.05){ cout<<fixed<<setprecision(1)<<jiashi; if(jiaxu>=0.05){ cout<<fixed<<setprecision(1)<<"+"<<jiaxu<<"i"<<endl; } else if(jiaxu<=-0.05){ cout<<fixed<<setprecision(1)<<jiaxu<<"i"<<endl; } else{ cout<<endl; } } else{ if(abs(jiaxu)>=0.05) cout<<fixed<<setprecision(1)<<jiaxu<<"i"<<endl; else{ cout<<"0.0"<<endl; } } cout<<fixed<<setprecision(1)<<"("<<a1; if(i1>=0){ cout<<"+"; } cout<<i1<<"i"<<") - ("<<a2; if(i2>=0){ cout<<"+"; } cout<<i2<<"i) = "; if(abs(jianshi)>=0.05){ cout<<fixed<<setprecision(1)<<jianshi; if(jianxu>=0.05){ cout<<fixed<<setprecision(1)<<"+"<<jianxu<<"i"<<endl; } else if(jianxu<=-0.05){ cout<<fixed<<setprecision(1)<<jianxu<<"i"<<endl; } else{ cout<<endl; } } else{ if(abs(jianxu)>=0.05) cout<<fixed<<setprecision(1)<<jianxu<<"i"<<endl; else{ cout<<"0.0"<<endl; } } cout<<fixed<<setprecision(1)<<"("<<a1; if(i1>=0){ cout<<"+"; } cout<<i1<<"i"<<") * ("<<a2; if(i2>=0){ cout<<"+"; } cout<<i2<<"i) = "; if(abs(chengshi)>=0.05){ cout<<fixed<<setprecision(1)<<chengshi; if(chengxu>=0.05){ cout<<fixed<<setprecision(1)<<"+"<<chengxu<<"i"<<endl; } else if(chengxu<=-0.05){ cout<<fixed<<setprecision(1)<<chengxu<<"i"<<endl; } else{ cout<<endl; } } else{ if(abs(chengxu)>=0.05) cout<<fixed<<setprecision(1)<<chengxu<<"i"<<endl; else{ cout<<"0.0"<<endl; } } cout<<fixed<<setprecision(1)<<"("<<a1; if(i1>=0){ cout<<"+"; } cout<<i1<<"i"<<") / ("<<a2; if(i2>=0){ cout<<"+"; } cout<<i2<<"i) = "; if(abs(chushi)>=0.05){ cout<<fixed<<setprecision(1)<<chushi; if(chuxu>=0.05){ cout<<fixed<<setprecision(1)<<"+"<<chuxu<<"i"<<endl; } else if(chuxu<=-0.05){ cout<<fixed<<setprecision(1)<<chuxu<<"i"<<endl; } else{ cout<<endl; } } else{ if(abs(chuxu)>=0.05) cout<<fixed<<setprecision(1)<<chuxu<<"i"<<endl; else{ cout<<"0.0"<<endl; } } return 0; }
相關推薦
5-36 複數四則運算 (15分)
#include<iostream> #include<cstdio> #include<iomanip> #include<cmath> using namespace std; int main() { double
5-10 計算工資 (15分)
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #in
5-19 支票面額 (15分)C語言
5-19 支票面額 (15分) 一個採購員去銀行兌換一張yy元ff分的支票,結果出納員錯給了ff元yy分。採購員用去了nn分之後才發覺有錯,於是清點了餘額尚有2y2y元2f2f分,問該支票面額是多少? 輸入格
5-25 念數字 (15分)
#include <iostream> #include <string.h> #include <map> #include <stdio.h> #
7-36 復數四則運算(15 分)
浮點數比較 分開 2.0 turn 測試 比較 print can double 7-36 7-36 復數四則運算(15 分) 本題要求編寫程序,計算2個復數的和、差、積、商。 輸入格式: 輸入在一行中按照a1 b1 a2 b2的格式給出2個復數C1=a1+b1i和C2=a
習題2.5 兩個有序鏈表序列的合並(15 分)浙大版《數據結構(第2版)》題目集
merge 其中 接口 cnblogs oid color 給定 style bsp 本題要求實現一個函數,將兩個鏈表表示的遞增整數序列合並為一個非遞減的整數序列。 函數接口定義: List Merge( List L1, List L2 ); 其中Lis
習題2.5 兩個有序鏈表序列的合並(15 分)<有疑問?L1 L2 沒辦法變空>
測試 bsp rto 標準 結構定義 tail ret 回歸 一個 習題2.5 兩個有序鏈表序列的合並(15 分) 本題要求實現一個函數,將兩個鏈表表示的遞增整數序列合並為一個非遞減的整數序列。 函數接口定義: List Merge( List L1, List
7-5 找最長的字串 (15 分)
本題要求編寫程式,針對輸入的N個字串,輸出其中最長的字串。 輸入格式: 輸入第一行給出正整數N;隨後N行,每行給出一個長度小於80的非空字串,其中不會出現換行符,空格,製表符。 輸出格式: 在一行中用以下格式輸出最長的字串: The longest is: 最長的字串 如
7-5 字串轉換成十進位制整數 (15 分) 測試點 2 測試
7-5 字串轉換成十進位制整數 (15 分) 輸入一個以#結束的字串,本題要求濾去所有的非十六進位制字元(不分大小寫),組成一個新的表示十六進位制數字的字串,然後將其轉換為十進位制數後輸出。如果在第一個十六進位制字元之前存在字元“-”,則代表該數是負數。 輸入格式: 輸
PAT基礎程式設計 5-14 求整數段和 (15分)
5-14 求整數段和 (15分) 給定兩個整數AA和BB,輸出從AA到BB的所有整數以及這些數的和。 輸入格式: 輸入在一行中給出2個整數AA和BB,其中-100<= A<=B<=100 −100≤A≤B≤100,其間以空格分隔。
1051 複數乘法 (15 分)
1051 複數乘法 (15 分) 複數可以寫成 (A+Bi) 的常規形式,其中 A 是實部,B 是虛部,i 是虛數單位,滿足 i2=−1;也可以寫成極座標下的指數形式 (R×e(Pi)
7-5 交換最小值和最大值(15 分)
7-5 交換最小值和最大值(15 分) 本題要求編寫程式,先將輸入的一系列整數中的最小值與第一個數交換,然後將最大值與最後一個數交換,最後輸出交換後的序列。 注意:題目保證最大和最小值都是唯一
5-1 字串轉換成十進位制整數 (15分) (這是補上的7月6號)
5-1 字串轉換成十進位制整數 (15分) 輸入一個以#結束的字串,本題要求濾去所有的非十六進位制字元(不分大小寫),組成一個新的表示十六進位制數字的字串,然後將其轉換為十進位制數後輸出。如果在第一個十六進位制字元之前存在字元“-”,則代表該數是負數。 輸入
7-5 輸出整數各位數字(15 分)
一、題目 二、個人理解 此題估計出題人是想我們不斷地進行取位數來做,但是實際上我們直接用字串輸入,再輸出即可。 C語言: #include <stdio.h> #in
理解 Linux CPU 負載 1分5分15分
本帖最後由 ulovko 於 2013-03-06 15:18 編輯 You might be familiar with Linux load averages already. Load averages are the three numbers shown with the uptime and t
5-29 求整數序列中出現次數最多的數 (15分)
5-29 求整數序列中出現次數最多的數 (15分) 本題要求統計一個整型序列中出現次數最多的整數及其出現次數。 輸入格式: 輸入在一行中給出序列中整數個數N(0<<N\le≤1
5-1 正整數A+B (15分)
題的目標很簡單,就是求兩個正整數A和B的和,其中A和B都在區間[1,1000]。稍微有點麻煩的是,輸入並不保證是兩個正整數。 輸入格式: 輸入在一行給出A和B,其間以空格分開。問題是A和B不一定
實驗5-3 使用函式求奇數和 (15分)
http://pta.patest.cn/pta/test/13/exam/3/question/461 #include <stdio.h> #define MAXN 1
5-17 求階乘序列前N項和 (15分)
本題要求編寫程式,計算序列 1!+2!+3!+⋯1! + 2! + 3! + \cdots1!+2!+3!+⋯ 的前N項之和。 輸入格式: 輸入在一行中給出一個不超過12的正整數N。 輸出格
5-14 求平方根序列前N項和 (15分)
本題要求編寫程式,計算平方根序列1+2+3+⋯\sqrt{1} + \sqrt{2} + \sqrt{3} + \cdots√1+√2+√3+⋯的前N項之和。可包