使用者工具

網站工具


You are not allowed to perform this action
c:2025fall-hw1

C Turnin作業1

國立屏東大學 資訊工程系 程式設計(一)

Turnin作業1

  • Turnin Code: c.hw1
  • Due Date: 2025/09/16 23:59 Hard Deadline

繳交方式說明

本次Turnin作業包含5個程式題,建議可以為它們建立一個資料夾,並將此次作業所有要上傳的檔案放置於該資料夾後,再使用 turnin 指令上傳作業。例如下面的操作在同學的家目錄裡建立了一個名為hw1的資料夾,並且切換到該資料夾後,針對第1題所要求的DoMath.c進行程式編撰:

[user@ws ~]$ mkdir hw1
[user@ws ~]$ cd hw1
[user@ws hw1]$ joe DoMath.c

等到我們完成DoMath.c的撰寫後,請自行加以編譯與執行程式,確認正確後使用 turnin▴c.hw1▴DoMath.c↵ 指令將加以上傳:

[user@ws c.hw1]$ turnin c.hw1 DoMath.c 
Turning in:
 DoMath.c -- ok
All done.
[user@ws c.hw1]$ 

當然,你也可以等到本次作業要求的所有題目都在hw1資料夾裡完成後,再使用 turnin▴c.hw1▴.↵ 指令一次將所有在目前資料夾中的所有檔案都加以上傳。假設你已經在hw1資料夾裡撰寫完所有題目,並且每個題目的程式檔案皆已編譯並確認執行結果正確後,我們可以使用以下指令將多餘的(不需要繳交的)檔案加以刪除後,一次將所有檔案繳交:

[user@ws c.hw1]$ ls
a.out  DoMath.c  Price.c  Reverse.c  TimeConvert.c  YearConvert.c
[user@ws c.hw1]$ rm a.out
[user@ws c.hw1]$ ls
DoMath.c  Price.c  Reverse.c  TimeConvert.c  YearConvert.c
[user@ws c.hw1]$ turnin c.hw1 .
Turning in:
 ./YearConvert.c -- ok
 ./TimeConvert.c -- ok
 ./Reverse.c -- ok
 ./Price.c -- ok
 ./DoMath.c -- ok
All done.
[user@ws c.hw1]$ 

如果繳交後想要查看已繳交的檔案及相關資訊,可以輸入turnin▴-ls▴c.hw1↵ 指令,例如:

[user@ws c.hw1]$ turnin -ls c.hw1
.:
total 20
-rw-rw----. 1 turninman turnin 227 Sep  8 14:38 DoMath.c
-rw-rw----. 1 turninman turnin 295 Sep  8 14:38 Price.c
-rw-rw----. 1 turninman turnin 254 Sep  8 14:38 Reverse.c
-rw-rw----. 1 turninman turnin 315 Sep  8 14:38 TimeConvert.c
-rw-rw----. 1 turninman turnin 228 Sep  8 14:38 YearConvert.c
[user@ws c.hw1]$ 
註:本文使用▴及↵代表空白字元與Enter換行字元,並且將使用者輸入的部份使用灰階方式顯示。另外,出現在程式執行結果中的符號皆為半形。


p1 算術運算(DoMath.c)

請設計一個C語言程式DoMath.c,讓使用者依序輸入兩個int整數變數x與y的數值後,計算 4x + 2y 的結果後加以輸出。本題的輸出結果可以參考如下:

[7:17 user@ws in hw1] ./a.out↵
Please▴input▴x:▴3↵
Please▴input▴y:▴5↵
(▴4x▴+▴2y▴)▴=▴22.↵
[7:17 user@ws in hw1] ./a.out↵
Please▴input▴x:▴10↵
Please▴input▴y:▴12↵
(▴4x▴+▴2y▴)▴=▴64.↵
[7:17 user@ws in hw1]

p2 民國年轉西元年(YearConvert.c)

請設計一個C語言的程式YearConvert.c,用以轉換民國年到西元年。此程式的執行結果可參考以下的輸出內容:

小提示: 本題僅會輸入民國1年(含)後的年份

[7:17 user@ws in hw1] ./a.out↵
Please▴input▴a▴year▴in▴ROC:▴114↵
ROC▴114▴is▴AD▴2025.↵
[7:17 user@ws in hw1] ./a.out↵
Please▴input▴a▴year▴in▴ROC:▴72↵
ROC▴72▴is▴AD▴1983.↵
[7:17 user@ws in hw1] ./a.out↵
Please▴input▴a▴year▴in▴ROC:▴100↵
ROC▴100▴is▴AD▴2011.↵
[7:17 user@ws in hw1]

p3 秒數轉時分秒(TimeConvert.c)

請設計一個 C 程式 TimeConvert.c,讀入一個「非負整數秒數」S,將其換算為「小時:分鐘:秒」的格式並輸出。

[3:23 user@ws hw] ./a.out↵
Enter▴seconds:▴7322↵
Converted▴time:▴2:2:2↵
[3:23 user@ws hw] ./a.out↵
Enter▴seconds:▴3600↵
Converted▴time:▴1:0:0↵
[3:23 user@ws hw] ./a.out↵
Enter▴seconds:▴105↵
Converted▴time:▴0:1:45↵
[3:23 user@ws hw]

p4 計算價格(Price.c)

請設計一個C語言的程式Price.c,讓使者輸入產品的價格(price)及購買的數量(quantity),假設使用者所輸入的值皆為大於0的正整數,請計算消費者購買產品的總價後輸出,其執行結果可參考以下的內容:

[7:17 user@ws in hw1] ./a.out↵
Please▴input▴the▴price:▴50↵
Please▴input▴the▴quantity:▴6↵
The▴total▴price▴is▴NT$300.↵
[7:17 user@ws in hw1] ./a.out↵
Please▴input▴the▴price:▴18↵
Please▴input▴the▴quantity:▴2↵
The▴total▴price▴is▴NT$36.↵
[7:17 user@ws in hw1]

p5 反轉數字(Reverse.c)

請設計一個C語言程式Reverse.c,讓使用者輸入為一個大於等於10,並且小於等於99的兩位數,將其十位數與個位數交換後加以輸出,其執行結果可參考如下:

[7:17 user@ws in hw1] ./a.out↵
Please▴input▴a▴two-digit▴number▴(10-99):▴53↵
The▴reversed▴number▴is▴35!↵
[7:17 user@ws in hw1] ./a.out↵
Please▴input▴a▴two-digit▴number▴(10-99):▴17↵
The▴reversed▴number▴is▴71!↵
[7:17 user@ws in hw1]

【提示:可以使用除法 / 以及餘除 % 來取得兩個整數相除的商及餘數。】

c/2025fall-hw1.txt · 上一次變更: 2025/09/10 07:14 由 mingfa

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki