




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、c語言大學(xué)教程1計算機科學(xué)與技術(shù)系計算機科學(xué)與技術(shù)系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計算兩個數(shù)中的最小者計算兩個數(shù)中的最小者. 2022-3-623/61ABNYNS圖圖傳統(tǒng)流程圖傳統(tǒng)流程圖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:復(fù)合語句復(fù)合語句compound statement被當(dāng)作一條語句看待被當(dāng)作一條語句看待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當(dāng)當(dāng)t 18時,為低體重;時,為低體重;當(dāng)當(dāng)18 t 25時,為正常體重;時,為正常體重;當(dāng)當(dāng)25 t 27時,為超重體重;時,為超重體重;當(dāng)當(dāng)t 27時,為肥胖。時,為肥胖。2022-3-650/61當(dāng)當(dāng)t 18時,為低體重;時,為低體重;當(dāng)當(dāng)18 t 25時,為正常體重;時,為正常體重;當(dāng)當(dāng)25 t 27時,為超重體重;時,為超重體重;當(dāng)當(dāng)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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司搬家引流活動方案
- 公司滿減活動策劃方案
- 公司盛大慶典活動方案
- 公司組織插畫活動方案
- 公司簽單活動方案
- 公司程序員團建活動方案
- 公司職工聚會活動方案
- 公司終年慶晚宴策劃方案
- 公司放電影活動方案
- 公司清明節(jié)創(chuàng)意活動方案
- 荊州中學(xué)2024-2025學(xué)年高二下學(xué)期6月月考?xì)v史試卷
- 2025-2030年中國婚慶產(chǎn)業(yè)行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 2024-2025學(xué)年蘇教版四年級下學(xué)期期末測試數(shù)學(xué)試卷(含答案)
- 2025年新高考2卷(新課標(biāo)Ⅱ卷)英語試卷
- 2025年中考化學(xué)必考要點知識歸納
- 三年級語文下冊全冊重點知識點歸納
- 公路養(yǎng)護材料管理制度
- JG/T 330-2011建筑工程用索
- 單位消防培訓(xùn)課件教學(xué)
- 項目可行性研究報告風(fēng)險管理與應(yīng)急措施制定策略
- 2024年湖北省初中學(xué)業(yè)水平考試地理試卷含答案
評論
0/150
提交評論