下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、算法與程序設(shè)計(jì)單元復(fù)習(xí)一、程序設(shè)計(jì)(寫出實(shí)現(xiàn)流程圖虛線框部分的程序代碼)1YN開始a>0?b=-a結(jié)束輸出bb=a輸入一個(gè)實(shí)數(shù)a23YN開始i<100i=1,s=0s=s+i結(jié)束輸出si=i+34NY開始i<=100?i=1i=i+1結(jié)束輸出sumsum=sum+1/isum=0YYN開始i<=5ss+xii+1結(jié)束輸出ss0,i1x>0?N輸入x56NYNY開始x<0?c1=0,c2=0c2=c2+1結(jié)束輸入x輸出c1,c2x<>0?c1=c1+17已知n個(gè)數(shù),編程求這n個(gè)數(shù)的(1)總和(2)平均值(3)最大值(4)最小值(5)正數(shù)和負(fù)數(shù)的個(gè)數(shù)
2、附錄:參考答案第一題:Private Sub Command1_Click() Dim a As Integer Dim b As Integer a = InputBox("請輸入數(shù)據(jù)a") If a < 0 Then b = -a Else b = a End If Print bEnd Sub第二題:Private Sub Command2_Click() Dim x As Integer Dim y As Integer a = 800: b = 1000 x = InputBox("請輸入數(shù)據(jù)x") If x < a Then y
3、= 0 Else If x < b Then y = 10 Else y = 20 End If End If Print yEnd Sub第三題:Private Sub Command3_Click()Dim i As Integer, s As Integeri = 1: s = 0Do s = s + i i = i + 3Loop While i < 100Print sEnd Sub第四題:Private Sub Command4_Click()Dim i As Integer, sum As Singlei = 1: sum = 0Do While i <= 10
4、0 sum = sum + 1 / i i = i + 1LoopPrint sumEnd Sub第五題:Private Sub Command5_Click()Dim i As Integer, s As Integer, x As Singles = 0: i = 1Do While i <= 5 x = InputBox("請輸入數(shù)據(jù)x") If x > 0 Then s = s + x End If i = i + 1 LoopPrint sEnd Sub第六題:Private Sub Command6_Click()Dim x As Single, c
5、1 As Integer, c2 As Integerc1 = 0: c2 = 0Do While i < 5 x = InputBox("請輸入數(shù)據(jù)x") If x <> 0 Then If x < 0 Then c1 = c1 + 1 Else c2 = c2 + 1 End If End If i = i + 1LoopPrint c1, c2End Sub第六題(數(shù)組):Private Sub Command7_Click()Dim x(1 To 5) As IntegerDim c1 As Integer, c2 As IntegerFor
6、 i = 1 To 5x(i) = InputBox("請輸入第" & i & "個(gè)數(shù)據(jù):")If x(i) <> 0 ThenIf x(i) < 0 Then c1 = c1 + 1 Else c2 = c2 + 1 End If End IfNext iPrint c1, c2End Sub第七題(1):Private Sub Command8_Click()Dim sum As Single, i As IntegerDim n As Integer, x As Integersum = 0i = 1n = Inp
7、utBox("n:")Do While i <= n x = InputBox("x:") sum = sum + x i = i + 1LoopPrint sumEnd Sub第七題(2):Private Sub Command9_Click()Dim sum As Single, i As IntegerDim n As Integer, x As Integersum = 0i = 1n = InputBox("n:")Do While i <= n x = InputBox("x:") sum
8、= sum + x i = i + 1LoopPrint sum / nEnd Sub第七題(3):Private Sub Command10_Click()Dim d(1 To 100) As IntegerDim i As Integer, temp As Integer, j As Integern = InputBox("請輸入數(shù)據(jù):")For i = 1 To nd(i) = InputBox("請輸入第" & i & "個(gè)數(shù)據(jù):")NextFor i = 2 To n For j = n To i Step
9、 -1 If d(j) < d(j - 1) Then temp = d(j): d(j) = d(j - 1): d(j - 1) = temp End If Next jNext iPrint d(n)End Sub第七題(3)不用數(shù)組:Private Sub Command13_Click()Dim x As Single, max As SingleDim i As Integer, n As Integern = InputBox("請輸入數(shù)據(jù)n:")x = InputBox("請輸入數(shù)據(jù)x:")i = 1max = xDo While
10、i < nx = InputBox("請輸入數(shù)據(jù)x:") If x > max Then max = x End If i = i + 1LoopPrint maxEnd Sub第七題(4):Private Sub Command11_Click()Dim d(1 To 100) As IntegerDim i As Integer, temp As Integer, j As Integern = InputBox("請輸入數(shù)據(jù):")For i = 1 To nd(i) = InputBox("請輸入第" & i
11、 & "個(gè)數(shù)據(jù):")NextFor i = 2 To n For j = n To i Step -1 If d(j) < d(j - 1) Then temp = d(j): d(j) = d(j - 1): d(j - 1) = temp End If Next jNext iPrint d(1)End Sub第七題(4)不用數(shù)組:Private Sub Command14_Click()Dim x As Single, min As SingleDim i As Integer, n As Integern = InputBox("請輸入數(shù)據(jù)n:")x = InputBox("請輸入數(shù)據(jù)x:")i = 1min = xDo While i < nx = InputBox("請輸入數(shù)據(jù)x:") If x < min Then min = x End If i = i + 1LoopPrint minEnd Sub第七題(5):Private Sub Command12_Click()Dim c1 As Integer, c2 As
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年甲乙雙方關(guān)于新一代智能電氣安裝工程全面合作合同
- 2024招投標(biāo)管理部門風(fēng)險(xiǎn)防控及合同履行責(zé)任書3篇
- 浙江工商大學(xué)《地貌學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 2024蘇州二手房買賣與家居智能化改造服務(wù)合同3篇
- 貨代公司知識(shí)培訓(xùn)課件
- 商品基礎(chǔ)知識(shí)培訓(xùn)課件
- 稅務(wù)工作總結(jié)稅收違法違章行為查處整改
- 2024智能供應(yīng)鏈管理系統(tǒng)建設(shè)與運(yùn)營合同
- 房屋租賃行業(yè)市場營銷策略總結(jié)
- 西南財(cái)經(jīng)大學(xué)《商務(wù)實(shí)踐活動(dòng)一》2023-2024學(xué)年第一學(xué)期期末試卷
- 檢驗(yàn)科lis系統(tǒng)需求
- 疏散樓梯安全要求全解析
- 汽車擾流板產(chǎn)品原材料供應(yīng)與需求分析
- 中東及非洲空氣制水機(jī)行業(yè)現(xiàn)狀及發(fā)展機(jī)遇分析2024-2030
- DL∕T 1631-2016 并網(wǎng)風(fēng)電場繼電保護(hù)配置及整定技術(shù)規(guī)范
- PLC控制系統(tǒng)合同(2024版)
- 煤礦立井井筒及硐室設(shè)計(jì)規(guī)范
- 房地產(chǎn)項(xiàng)目開發(fā)合作協(xié)議書
- JJG(交通) 171-2021 超聲式成孔質(zhì)量檢測儀檢定規(guī)程
- QCT457-2023救護(hù)車技術(shù)規(guī)范
- 《中國大熊貓》課件大綱
評(píng)論
0/150
提交評(píng)論