




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、c語言大學教程1計算機科學與技術系計算機科學與技術系2022-3-62/612022-3-63/612022-3-64/612022-3-65/612022-3-66/612022-3-67/612022-3-68/612022-3-69/612022-3-610/612022-3-611/612022-3-612/612022-3-613/61Start/EndProcessInput/OutputTestConnectorFlow of activities2022-3-614/612022-3-615/61 2022-3-616/61 2022-3-617/61main() scanf(
2、%d, &quantity); scanf(%d, &pricePerkg); price = quantity*pricePerkg; printf(%d, price); 2022-3-618/61main() int quantity,price_per_kg,price; scanf(%d, &quantity); scanf(%d, &pricePerkg); price = quantity*pricePerkg; printf(%d, price); 2022-3-619/61main() int quantity,price_per_kg,pri
3、ce; scanf(%d, &quantity); scanf(%d, &pricePerkg); price = quantity*pricePerkg; printf(%d, price); 2022-3-620/612022-3-621/61NS圖2022-3-622/61計算兩個數中的最小者計算兩個數中的最小者. 2022-3-623/61ABNYNS圖圖傳統流程圖傳統流程圖2022-3-624/61 2022-3-625/61 2022-3-626/61main() int num1, num2, min; scanf(%d%d, &num1, &nu
4、m2); if (num1 num2) min =num1; else min = num2; printf(%d, min); 2022-3-627/612022-3-628/61step aif startstep mstep nend_ifstep b2022-3-629/61Syntax:復合語句復合語句compound statement被當作一條語句看待被當作一條語句看待2022-3-630/61Syntax:2022-3-631/61Single Selection Pseudocode :if startstep 1step 2step kend_if Statement:if
5、 (expression) statement 1statement 2statement k2022-3-632/61main() int num1, num2, min; printf(“Input 2 numbers: “); scanf(“%d%d”, &num1, &num2); min = num1; if (num1 num2)min = num2; printf(“Smallest: %dn”, min);Input 2 numbers: _num2?num1?min?Input 2 numbers: 20 15_20152015Input 2 numbers:
6、 20 15Smallest: 15_2022-3-633/61Example:main() int mark;scanf(“%d”, &mark);if (mark = 60)printf(“Passn”);printf(“Your mark is %d”, mark);2022-3-634/61Example:main() int mark;scanf(“%d”, &mark);if (mark = 60)printf(“Passn”);printf(“Your mark is %d”, mark);2022-3-635/61Step aif startStep mStep
7、 nend_ifelse startStep xStep yend_elseStep z2022-3-636/61Syntax:oror2022-3-637/61Double Selection Pseudocode:if startstep 1step kend_ifelse startstep 1step nend_else Statement:if (expression) statement 1statement kelse statement 1statement n2022-3-638/61Example:if (num1 num2)min = num1;elsemin = num
8、2;printf(“Smallest: %dn”, min);num215num1min?_10Smallest: 10_2022-3-639/61Example:if (num1 num2)min = num1;elsemin = num2;printf(“Smallest: %dn”, min);num215num1min?_15Smallest: 15_2022-3-640/61if (num1 num2) min = num1;max = num2;else min = num2;max = num1;printf(“Min = %d, Max = %dn”, min, max);nu
9、m2125num1700min?_max?Min = 125, Max = 700_1257002022-3-641/61if (num1 num2)min = num1;elsemin = num2;printf(“Smallest: %dn”, min);min = num1 num2 num1 num2;printf(“Smallest: %dn”, min);2022-3-642/612022-3-643/61step aif (expression) step mstep nstep b2022-3-644/61step aif startstep mstep nend_ifstep
10、 bstep aif (expression) step mstep nelse step xstep ystep bGuesshow does multiple selection look like ?2022-3-645/61Step a (expression1)Step m (expression2) Step n Step z2022-3-646/61Step a(expression1) Step m (expression2) Step n Step x Step z2022-3-647/61Step a(表達式表達式1) Step 1 (表達式表達式2) Step 2 (表達
11、式表達式3) Step 3 () Step Step n Step zexpr1step 1非0=0expr2expr3Step nStep 3Step 2非0非0=0=0Step aStep z2022-3-648/612022-3-649/61當當t 18時,為低體重;時,為低體重;當當18 t 25時,為正常體重;時,為正常體重;當當25 t 27時,為超重體重;時,為超重體重;當當t 27時,為肥胖。時,為肥胖。2022-3-650/61當當t 18時,為低體重;時,為低體重;當當18 t 25時,為正常體重;時,為正常體重;當當25 t 27時,為超重體重;時,為超重體重;當當t 2
12、7時,為肥胖。時,為肥胖。2022-3-651/61 (p1) (p2) A B(p4) C D (p1) A(p2) C D (p1) (p2) A BC (p1) (p2) A(p4) C D (p1) (p2) AC else與哪個與哪個if配套?配套?2022-3-652/61The structure is similar to multiple selection (flowchart)2022-3-653/61Important Rule !2022-3-654/61Example: switch (month) case 1:printf(“Januaryn”);break;c
13、ase 2:printf(“Februaryn”);break;case 3:printf(“Marchn”);break;default:printf(“Othersn”);break; printf(“End”);January_JanuaryEnd _2022-3-655/61Example: switch (month) case 1:printf(“Januaryn”);break;case 2:printf(“Februaryn”);break;case 3:printf(“Marchn”);break;default:printf(“Othersn”);break; printf
14、(“End”);March_MarchEnd _2022-3-656/61Example: switch (month) case 1:printf(“Januaryn”);break;case 2:printf(“Februaryn”);break;case 3:printf(“Marchn”);break;default:printf(“Othersn”);break; printf(“End”);2022-3-657/61Example: switch (month) case 1:printf(“Januaryn”);break;case 2:printf(“Februaryn”);c
15、ase 3:printf(“Marchn”);break;default:printf(“Othersn”);break; printf(“End”);2022-3-658/61Example: switch (month) case 1:printf(“Januaryn”);break;case 2:printf(“Februaryn”);case 3:printf(“Marchn”);break;default:printf(“Othersn”);break; printf(“End”);February_ March _ End _2022-3-659/61Example: switch (month) case 1:printf(“Januaryn”);break;case 2:printf(“Februaryn”);case 3:printf(“Marchn”);break;default:printf(“
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《化學反應中物質的轉化:高中化學重點解析》
- 電子競技賽事策劃組織協議
- 市場推廣合同事項說明
- 財務成本控制與預算編制測試卷
- 意外險考試試題及答案
- 六一創新班級活動方案
- 六一居家活動方案
- 六一慶祝關愛活動方案
- 六一手工店活動方案
- 六一活動勞動篇活動方案
- 2025年新高考2卷(新課標Ⅱ卷)英語試卷
- 制造企業加班管理制度
- 兒童疼痛的評估及護理措施
- 護理試卷試題及答案
- 人文社科班試題及答案
- 2025年公路水運工程重大事故隱患判定標準
- 通風維修質保合同協議
- 土地托管合同協議書范本
- 中國餐廚垃圾處理的現狀、問題和對策
- 實習生轉正綜合素質與協議
- GB/T 2423.65-2024環境試驗第2部分:試驗方法試驗:鹽霧/溫度/濕度/太陽輻射綜合
評論
0/150
提交評論