vb第四章選擇結(jié)構(gòu)和循環(huán)結(jié)構(gòu)編程題_第1頁
vb第四章選擇結(jié)構(gòu)和循環(huán)結(jié)構(gòu)編程題_第2頁
vb第四章選擇結(jié)構(gòu)和循環(huán)結(jié)構(gòu)編程題_第3頁
vb第四章選擇結(jié)構(gòu)和循環(huán)結(jié)構(gòu)編程題_第4頁
vb第四章選擇結(jié)構(gòu)和循環(huán)結(jié)構(gòu)編程題_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上 第四章編程題 1.查詢分數(shù)題Private Sub Form_Load()x = Val(InputBox("請輸入分數(shù)", "輸入", 0)Select Case xCase Is < 0Label1.Caption = "輸入有誤"Case Is > 100Label1.Caption = "輸入有誤"Case Is >= 90Label1.Caption = "優(yōu)秀"Case Is >= 80Label1.Caption = "

2、良好"Case Is >= 70Label1.Caption = "一般"Case Is >= 60Label1.Caption = "及格"Case Is < 60Label1.Caption = "不及格"End SelectEnd Sub2.求最大公約數(shù)題Private Sub Command1_Click()Dim m As Integer, n As Integer, p As Integerm = Val(Text1.Text)n = Val(Text2.Text)If m < 0 Or

3、n < 0 Then MsgBox "數(shù)據(jù)錯誤!" EndEnd Ifp = m Mod nDo While p <> o m = n n = p p = m Mod nLoopText3.Text = nEnd Sub2.1最小公倍數(shù)Private Sub Command1_Click()Dim m As Integer, n As Integer, p As Integer, t As Integerm = Val(Text1.Text)n = Val(Text2.Text)t = m * nIf m < 0 Or n < 0 ThenMs

4、gBox "數(shù)據(jù)錯誤!"EndEnd IfIf m = 0 Or n = 0 ThenText3.Text = 0ElseDop = m Mod nIf p = 0 ThenExit DoEnd Ifm = nn = pLoop Until FalseText3.Text = t / nEnd IfEnd Sub3. 九九乘法表Private Sub Command1_Click() Dim I As Integer, J As Integer, M As Integer, s As String For I = 1 To 9 s = "" For J

5、= 1 To I M = I * J s = s & J & "*" & I & "=" & M & " " Next J List1.AddItem s Next IEnd Sub4.求ABCDCDC=ABC題Private Sub Command1_Click()For a = 1 To 9: For b = 0 To 9For c = 1 To 9: For d = 0 To 9x = a * 1000 + b * 100 + 10 * c + dy = c * 100 + d *

6、 10 + cz = a * 100 + b * 10 + cIf x - y = z ThenPrint x; y; zEnd IfNextNextNextNextEnd Sub5. 求前100項和,平均數(shù)題Private Sub Form_click()n = 1: s = 0Do While n <= 100s = s + nn = n + 1LoopPrint s, n - 1, s / (n - 1), s * (n - 1)End Sub6.輸入10個數(shù)找出正數(shù),負數(shù),零的個數(shù)Private Sub Command1_Click() Dim i, t, x1, x2, x3

7、As Integer For i = 1 To 10 t = Val(InputBox("請輸入第" & i & "個數(shù):", "顯示", 0) If t > 0 Then x1 = x1 + 1 ElseIf t < 0 Then x2 = x2 + 1 Else x3 = x3 + 1 End If Next Print "正數(shù)的個數(shù):" & x1 Print "負數(shù)的個數(shù):" & x2 Print "零的個數(shù):" &

8、x3End Sub7. Fibonacci數(shù)列(用數(shù)組做)Private Sub Form_Load()For i = 1 To 30List1.AddItem Fib(i)NextEnd SubPrivate Function Fib(n)If n < 3 Then Fib = 1ElseFib = Fib(n - 1) + Fib(n - 2)End IfEnd FunctionPrivate Sub List1_Click()List1.AddItem = FibEnd Sub8.輸入十個數(shù)打印并找出最大數(shù),最小數(shù)Private Sub Command1_Click() Dim a

9、(9), i, max, min As Integer For i = 0 To 9 a(i) = Val(InputBox("請輸入第" & i + 1 & "個數(shù):") Print a(i); Next max = a(0) For i = 0 To 9 If a(i) > max Then max = a(i) If a(i) < min Then min = a(i) Next Print Print Print Print "最大數(shù)為:" & max; "最小數(shù)為:"

10、& minEnd Sub9.100元換成40張等值的10,5,2,1的錢的題Private Sub Command1_Click()For x = 1 To 10For y = 1 To 20For z = 1 To 50w = 40 - x - y - zIf 10 * x + 5 * y + 2 * z + w = 100 And x * y * z * w > 0 Thenh = Format(x, "") & Format(y, "") _& Format(z, "") & Format(

11、w, "")List1.AddItem hEnd IfNext zNext yNext xEnd Sub10.找出三位數(shù)的回文數(shù)并打印,并求其個數(shù)Private Sub Command1_Click()Dim n As Integer For n = 101 To 999 a = Int(n / 100) b = Int(n - a * 100) / 10) c = n - a * 100 - b * 10 If a = c Then List1.AddItem n Next Print List1.ListCountEnd Sub10-2回文字判斷1)按定義判斷 先求出字

12、符串的反序字符串,然后和原字符串比較,如果相等則是回文,否則不是回文。 Dim str As String, i As Integer '以下求Text1中文本的反序串str For i=1 To Len(Text1) str=Mid(Text1, i, 1) & str Next i If str=Text1 Then MsgBox "是回文" Else MsgBox "不是回文"(2)首尾字符的成對比較將字符串折半比較,若每對字符都相等則是回文,否則只要有一對字符不等就不是回文。 Dim i As Integer For i=1 To

13、 Len(Text1) 2 If Mid(Text1, i, 1) <> Mid(Text1, Len(Text1) - i + 1, 1) Then Exit For Next i If i > Len(Text1) 2 Then MsgBox "是回文" Else MsgBox "不是回文"11.求1-10之間階乘題Private Sub Command1_Click()Dim i As Integer, s As Double i = 1 Do While i <= 10 s = 1 For j = 1 To i s = s

14、 * j Next j Print i; "!=" s i = i + 1 LoopEnd Sub12.水仙花題Private Sub Command1_Click()Dim i As Integer, m As IntegerFor i = 100 To 999m = (i Mod 10) 3 + _(i 10 Mod 10) 3 + (i 100) 3If m = i Then Print iNext iEnd SubPrivate Sub Command2_Click()For a = 1 To 9: For b = 0 To 9: For c = 0 To 9x =

15、 a * 100 + b * 10 + cIf x = a 3 + b 3 + c 3 ThenPrint xEnd IfNextNextNextEnd Sub13. 打印菱形 Private Sub Command1_Click() For i = 1 To 5 Print Spc(6 - i); For j = 1 To i Print Spc(1); "*" Next j Print Next i For i = 5 To 1 Step -1 Print Spc(6 - i); For j = 1 To i Print Spc(1); "*" Ne

16、xt j Print Next iEnd Sub14.用Do循環(huán)設計例4.11中的s=1×2×3××n的值,其中n由輸入對話框獲得。Private Sub Command1_Click() n = InputBox("請輸入n的值:", "輸入") s = 1 i = 1 Do If i > Val(n) Then Exit Do s = s * i i = i + 1 Loop MsgBox "s=" + Str(s), 0, "計算結(jié)果"End Sub15. 求由數(shù)

17、字0、1、2、3、4組成的所有無重復數(shù)字的3位正整數(shù)。 Private Sub Command1_Click() Dim a As Integer, b As Integer, c As Integer, n As Integer For a=1 To 4 For b=0 To 4 For c=0 To 4 If a <> b And b <> c And a <> c Then Print a * 100 + b * 10 + c;或為 List1.AddItem a * 100 + b * 10 + c n=n + 1 If n Mod 5=0 Then

18、 Print End If Next c Next b Next aEnd Sub 課后題1.Private Sub Command1_Click()x = Val(InputBox("請輸入一個數(shù)", "顯示", 0)If x > 0 Then x = MsgBox("是正數(shù)", 48, 顯示)If x = 0 Then x = MsgBox("是零", 48, 顯示)If x < 0 Then x = MsgBox("是負數(shù)", 64, 顯示)End Sub2.Private S

19、ub Command1_Click()Dim a As SingleDim b As SingleDim c As SingleDim t As Singlea = Val(InputBox("請輸入第一個數(shù)", "從大到小排序", 0)b = Val(InputBox("請輸入第二個數(shù)", "從大到小排序", 0)c = Val(InputBox("請輸入第三個數(shù)", "從大到小排序", 0)If a < b Then t = a: a = b: b = tIf a

20、< c Then t = a: a = c: c = tIf b < c Then t = b: b = c: c = tPrint "從大到小的順序為:" a; b; cEnd Sub3.Private Sub Command1_Click()Static n As Integerx = Text1.TextIf x = "123" ThenLabel1.Caption = "歡迎進入本系統(tǒng)"ElseLabel1.Caption = "輸入錯誤" n = n + 1 If n = 3 Then End

21、 End IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""End Sub4.Private Sub Command1_Click()If Left(Text1.Text, 2) = 1 ThenText2.Text = "一年級"Else If Left(Text1.Text, 2) = 2 Then Text2.Text = "二年級" Else If Left(Text1.Text, 2) = 3 Then Text2.Text = "三年級" Else

22、If Left(Text1.Text, 2) = 4 Then Text2.Text = "四年級" Else Text2.Text = "輸入錯誤" End If End If End IfEnd IfIf Mid(Text1.Text, 5, 1) = 2 Then Text3.Text = "博士生"Else If Mid(Text1.Text, 5, 1) = 3 Then Text3.Text = "碩士生" Else If Mid(Text1.Text, 5, 1) = 4 Then Text3.Tex

23、t = "本科生" Else If Mid(Text1.Text, 5, 1) = 5 Then Text3.Text = "??粕?quot; Else Text3.Text = "輸入錯誤" End If End If End IfEnd IfEnd Sub5.Private Sub Command1_Click()Dim x As IntegerFor x = 100 To 200If x Mod 3 = 0 Or x Mod 5 = 0 ThenList1.AddItem xEnd IfNextPrint List1.ListCount

24、End Sub6.Private Sub Command1_Click()a = 1: b = 1List1.AddItem aList1.AddItem bFor n = 1 To 28c = a + ba = bb = cList1.AddItem cNextEnd Sub7. 完備數(shù)Private Sub Command1_Click() Dim m, i, j, s j = "結(jié)果:" For m = 2 To 1000 s = 0 For i = 1 To m - 1 If m Mod i = 0 Then s = s + i Next If s = m Then j = j & m & "," Next Print jEnd SubPrivate Sub Command2_Click()Dim m As Integer, s As IntegerFor

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論