C語言每日一題 PTA 基礎程式設計題 複數四則運算

2021-10-09 16:17:28 字數 1819 閱讀 8829

7-36 複數四則運算 (15分)

本題要求編寫程式,計算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

#include

struct fushu

;struct fushu computsum

(struct fushu a,

struct fushu b)

;//結構體函式

struct fushu computsub

(struct fushu a,

struct fushu b)

;//結構體函式

struct fushu computmul

(struct fushu a,

struct fushu b)

;//結構體函式

struct fushu computdiv

(struct fushu a,

struct fushu b)

;//結構體函式

void

myprintf

(struct fushu a,

struct fushu b,

char op,

struct fushu r )

;int

main()

struct fushu computsum

(struct fushu a,

struct fushu b)

//結構體函式

struct fushu computsub

(struct fushu a,

struct fushu b)

//結構體函式

struct fushu computmul

(struct fushu a,

struct fushu b)

//結構體函式

struct fushu computdiv

(struct fushu a,

struct fushu b)

//結構體函式

void

myprintf

(struct fushu a,

struct fushu b,

char op,

struct fushu r )

C語言每日一題(一)

當對乙個變數頻繁被讀寫時,需要反覆訪問記憶體,從而花費大量的訪問時間。為此,c語言提供了一種變數,即暫存器變數。這種變數存放在cpu的暫存器中,使用時,不需要訪問記憶體,而直接從暫存器中讀寫,從而提高效率。暫存器變數的說明符是register。對於迴圈次數較多的迴圈控制變數及迴圈體內反覆使用的變數均...

C 每日一題

題目 給定乙個陣列 nums 和乙個值 val 你需要原地移除所有數值等於 val 的元素,返回移除後陣列的新長度。不要使用額外的陣列空間,你必須在原地修改輸入陣列並在使用 o 1 額外空間的條件下完成,oj鏈結.解析 我們來解析一下這個題目的做題思路,他的含義就是讓我們刪除掉陣列中的元素,然後將陣...

程式設計每日一題 C程式設計 計算工資

描述 正確解法 include intmain else salary hour 50.00 else if hour 40 else salary hour 30.00 printf 2lf n salary return0 錯誤解法一 include intmain else salary ho...