版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1編寫(xiě)程序,求2的n次冪,n的值通過(guò)鍵盤(pán)輸入。(要求用循環(huán)做,非循環(huán)不給分。)Private Sub Command1_Click()Dim i As Long, n As Integer, s As Long n = Int(Val(InputBox("請(qǐng)輸入n的值" + "輸入框") s = 1 For i = 1 To n s = s * 2 Next i Print s End Sub2從鍵盤(pán)上輸入兩個(gè)正整數(shù)A和B,求最大公約數(shù)。Private Sub Command1_Click()Dim a As Integer, b As Integer,
2、 n As Integer, i As Integer a = Text1.Text b = Text2.Text If a < b Then i = a: a = b: b = i Do While b <> 0 n = a Mod b: a = b: b = n Loop Text3.Text = n End Sub3編寫(xiě)程序,隨機(jī)生成100個(gè)兩位整數(shù),并統(tǒng)計(jì)出其中小于等于40、大于40小于等于70及大于70的數(shù)據(jù)個(gè)數(shù)。Private Sub Form_Click()Dim n As IntegerDim cont1 As Integer, cont2 As Intege
3、r, cont3 As Integer n = Int(Rnd * 90 + 10) Print n cont1 = 0 cont2 = 0 cont3 = 0 If n < 40 Then cont1 = cont1 + 1 End If If n > 40 And n < 70 Then cont2 = cont2 + 1 End If If n > 70 Then cont3 = cont3 + 1 End If Print cont1: cont2: cont3 4編寫(xiě)程序,單擊窗體時(shí)在窗體上輸出如下所示的圖形。 * * * * * * * * *Private
4、 Sub Form_Click()Dim i As Integer, begin As Integerbegin = 5 For i = 1 To 5 Print Tab(begin); For j = 1 To 2 * i - 1 Print "*" Next j Print begin = begin - 1 Next i begin = 2 For i = 1 To 4 Print Tab(begin); For j = 1 To 9 - 2 * i Print "*" Next j Print begin = begin + 1 Next iEn
5、d Sub5編寫(xiě)程序,計(jì)算并輸出下面級(jí)數(shù)前n項(xiàng)(n=80)的部分和。 1-1/2+1/3-1/4+1/5+1/n(n由鍵盤(pán)輸入 ,要求用循環(huán)做,非循環(huán)不給分。)Private Sub Command1_Click() Dim n As Integer, i As Integer Dim sum As Double n = Val(InputBox("") sum = 0 For i = 1 To n If i Mod 2 <> 0 Then sum = sum + (1 / i) Else sum = sum - (1 / i) End If Next i Pr
6、int sumEnd Sub6有100匹馬,馱100擔(dān)貨:大馬馱3擔(dān),中馬馱2擔(dān),兩匹小馬馱1擔(dān),問(wèn)有大、中小馬各多少?Option ExplicitPrivate Sub Form_Click() Dim x As Integer, y As Integer, z As IntegerPrint "大馬", "中馬", "小馬" For x = 0 To 33 For y = 0 To 50 z = 100 - x - y If (x * 3 + y * 2 + z * 0.5) = 100 Then Print x, y, z E
7、nd If Next y Next x Print Print "共7種方案。"End Sub7編寫(xiě)程序,要求從鍵盤(pán)輸入0-6中的一任一個(gè),可對(duì)應(yīng)得到星期日、星期一-星期六。Private Sub Form_Click() Dim n As Integer n = Int(Val(InputBox("") Select Case n Case 0 Print n; ":星期日" Case 1 Print n; ":星期一" Case 2 Print n; ":星期二" Case 3 Print
8、n; ":星期三" Case 4 Print n; ":星期四" Case 5 Print n; ":星期五" Case 6 Print n; ":星期六" Case Else Print n; ":錯(cuò)誤" End SelectEnd Sub8編寫(xiě)程序,輸出下列三角形: (要求用循環(huán)做,非循環(huán)不給分。) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1Option ExplicitPrivate Sub Command1_Click() Dim i As Integer, j As
9、 Integer, begin As Integer begin = 7 For i = 1 To 4 Print Tab(begin); For j = 1 To 2 * i - 1 Print "1 " Next j Print begin = begin - 2 Next iEnd Sub9求公式:e=1/1!+1/2!+1/3!+1/n! 直到最后一項(xiàng)小于10(-6)時(shí)e的值。(注:程序代碼寫(xiě)在命令按鈕Command1的Click事件中。)Private Sub Command1_Click() Dim e As Double, nj As DoubleDim n
10、As Long, i As Long e = 0 n = 1 Do nj = 1 For i = 1 To n nj = nj * i Next i e = e + 1 / nj n = n + 1 Loop Until (1 / nj) < 0.000001 Print eEnd Sub10編寫(xiě)程序,輸出下列三角形: 總行數(shù)通過(guò)鍵盤(pán)輸入。(要求用循環(huán)做,非循環(huán)不給分。) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1Private Sub Command1_Click() Dim i As Integer, j As Integer, n As Integer, beg
11、in As Integer n = Int(Val(InputBox("") begin = 1 For i = 1 To n Print Tab(begin); For j = 1 To 9 - 2 * i Print "1 " Next j Print begin = begin + 2 Next iEnd Sub11輸入一串?dāng)?shù)字,求其中偶數(shù)位數(shù)字之和。例如輸入234567,則求357。Private Sub Command1_Click() Dim str As String, s As String * 1, i As Long, sum As
12、Long str = InputBox("") Print str sum = 0 For i = 2 To Len(str) Step 2 s = Mid(str, i, 1) sum = sum + Val(s) Print s Next i Print "+=" sumEnd Sub12編寫(xiě)程序,單擊窗體時(shí)在窗體上輸出如下所示的圖形。 * * * * * * * * *Private Sub Command1_Click() Dim begin As Integer, n As Integer, i As Long begin = 9 For i
13、= 1 To 5 Print Tab(begin); For n = 1 To 2 * i - 1 Print "*" Next n Print begin = begin - 2 Next i begin = 3 For i = 1 To 4 Print Tab(begin); For n = 1 To 9 - 2 * i Print "*" Next n Print begin = begin + 2 Next i End Sub13有一分?jǐn)?shù)序列:1 , 1/2 , 2/3 , 3/5 , 5/8 , 8/13 , 13/21 求出這個(gè)數(shù)列的前20項(xiàng)
14、之和。Private Sub Command1_Click() Dim sum As Double Dim a1 As Long, a2 As Long, a3 As Long Dim b1 As Long, b2 As Long, b3 As Long Dim i As Long a1 = 1: a2 = 1 b1 = 1: b2 = 2 sum = a1 / b1 + a2 / b2 For i = 2 To 20 a3 = a1 + a2 b3 = b1 + b2 sum = sum + a3 / b3 a1 = a2 a2 = a3 b1 = b2 b2 = b3 Next i Pri
15、nt sumEnd Sub14輸入一串?dāng)?shù)字,求其中奇數(shù)數(shù)字構(gòu)成的數(shù)與偶數(shù)數(shù)字構(gòu)成的數(shù)之差。例如輸入1654238,求1536428。Private Sub Command1_Click() Dim str As String, s1 As String, s2 As String, i As Long str = InputBox("") Print str s1 = "" s2 = "" For i = 1 To Len(str) If i Mod 2 = 1 Then s1 = s1 & Mid(str, i, 1) El
16、se s2 = s2 & Mid(str, i, 1) End If Next i Print s1; " - " s2; " = " Val(s1) - Val(s2) End Sub16編寫(xiě)程序,計(jì)算下面級(jí)數(shù)前n項(xiàng)中(n=50)奇數(shù)項(xiàng)的和,并輸出該級(jí)數(shù)最后兩項(xiàng)之差的絕對(duì)值。 (要求用循環(huán)做,非循環(huán)不給分。) 1*2*3+2*3*4+3*4*5+n*(n+1)*(n+2)+Private Sub Command1_Click() Dim sum As Double, plus As Double, n As Long sum = 0 For n
17、 = 1 To 50 Step 2 sum = sum + n * (n + 1) * (n + 2) Next n plus = (49 - 52) * 50 * 51 Print sum Print Abs(plus)End Sub17輸入3個(gè)數(shù)x,y,z,按大小順序把它們輸出來(lái)。Private Sub Command1_Click() Dim x As Double Dim y As Double Dim z As Double Dim t As Double x = Val(Text1.Text) y = Val(Text2.Text) z = Val(Text3.Text) If x
18、 < y Then t = x: x = y: y = t '交換x和y,使x>y End If If y < z Then t = y: y = z: z = t '交換y和z,使z最小 If x < y Then t = x: x = y: y = t '交換x和y,使x最大 End If End If Text1.Text = Str(x) Text2.Text = Str(y) Text3.Text = Str(z) End Sub19編程打印如下圖形,總行數(shù)通過(guò)鍵盤(pán)輸入。(要求用循環(huán)做,非循環(huán)不給分。按原圖形直接打印者無(wú)效。) 2 3
19、3 3 5 5 5 5 5 8 8 8 8 8 8 8 13 13 13 13 13 13 13 13 13Private Sub Command1_Click() Dim f1 As Long, f2 As Long, f3 As Long Dim n As Long, begin As Long Dim i As Long, j As Long n = Int(Val(InputBox("") begin = 4 * n - 3 f1 = 1 f2 = 1 For i = 1 To n f3 = f1 + f2 Print Tab(begin); For j = 1 T
20、o 2 * i - 1 Print Trim(f3); Spc(4 - Len(Trim(f3); Next j begin = begin - 4 f1 = f2 f2 = f3 Next i End Sub20編寫(xiě)程序,計(jì)算并輸出下面級(jí)數(shù)前n項(xiàng)(n=30)的部分和。 (要求用循環(huán)做,非循環(huán)不給分。) 1/(1*2)+1/(2*3)+1/(3*4)+1/(n*(n+1)+ Private Sub Command1_Click() Dim sum As Double, n As Long sum = 0 For n = 1 To 30 sum = sum + 1 / (n * (n + 1)
21、Next n Print sumEnd Sub22編寫(xiě)程序,輸出下列三角形: (要求用循環(huán)做,非循環(huán)不給分。) G FG EFG DEFG CDEFG BCDEFG ABCDEFGPrivate Sub Command1_Click() Dim code1 As Integer, code2 As Integer For code1 = Asc("G") To Asc("A") Step -1 For code2 = code1 To Asc("G") Print Chr(code2); Next code2 Print Next c
22、ode1End Sub23編寫(xiě)程序,計(jì)算下面級(jí)數(shù)前n項(xiàng)(n=20)的部分和,并輸出該級(jí)數(shù)最后兩項(xiàng)之差的絕對(duì)值。 (要求用循環(huán)做,非循環(huán)不給分。) 1*2*3+2*3*4+3*4*5+n*(n+1)*(n+2)+Private Sub Command1_Click() Dim sum As Double, plus As Double, n As Long sum = 0 For n = 1 To 20 sum = sum + n * (n + 1) * (n + 2) Next n plus = (19 - 22) * 20 * 21 Print sum Print Abs(plus) End Sub24勾股定理中三個(gè)數(shù)的關(guān)系是:a2 + b2 =c2 編寫(xiě)程序,輸出100以內(nèi)滿足上
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度中醫(yī)養(yǎng)生產(chǎn)品海外市場(chǎng)推廣合同4篇
- 2025年度商業(yè)綜合體承包轉(zhuǎn)讓合同范本4篇
- 2025年度養(yǎng)老機(jī)構(gòu)場(chǎng)地租賃與養(yǎng)老服務(wù)分成管理合同3篇
- 2025年cfg樁基施工項(xiàng)目環(huán)境保護(hù)與生態(tài)修復(fù)合同3篇
- 2025年度智能家電維修個(gè)人勞務(wù)協(xié)議書(shū)4篇
- 2025年中國(guó)酚氨咖敏顆粒行業(yè)發(fā)展?jié)摿Ψ治黾巴顿Y戰(zhàn)略咨詢報(bào)告
- 2025年度汽車(chē)租賃與二手車(chē)交易服務(wù)合同3篇
- 2025年溫州家和物業(yè)管理有限公司招聘筆試參考題庫(kù)含答案解析
- 2025年溫州個(gè)人房屋買(mǎi)賣(mài)合同(含交易資金監(jiān)管)3篇
- 二零二五版離婚協(xié)議書(shū)模板:離婚后子女撫養(yǎng)及財(cái)產(chǎn)分割專案協(xié)議2篇
- 氧氣霧化吸入法
- 6月大學(xué)英語(yǔ)四級(jí)真題(CET4)及答案解析
- 氣排球競(jìng)賽規(guī)則
- 電梯維修保養(yǎng)報(bào)價(jià)書(shū)模板
- 危險(xiǎn)化學(xué)品目錄2023
- FZ/T 81024-2022機(jī)織披風(fēng)
- GB/T 33141-2016鎂鋰合金鑄錠
- 2023譯林版新教材高中英語(yǔ)必修二全冊(cè)重點(diǎn)短語(yǔ)歸納小結(jié)
- JJF 1069-2012 法定計(jì)量檢定機(jī)構(gòu)考核規(guī)范(培訓(xùn)講稿)
- 綜合管廊工程施工技術(shù)概述課件
- 公積金提取單身聲明
評(píng)論
0/150
提交評(píng)論