南京工業(yè)大學(xué)VB期末考試編程題覆蓋范圍_第1頁(yè)
南京工業(yè)大學(xué)VB期末考試編程題覆蓋范圍_第2頁(yè)
南京工業(yè)大學(xué)VB期末考試編程題覆蓋范圍_第3頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、VB期末考試編程題覆蓋范圍: 第一題要求(15分): 不用過(guò)程,覆蓋以下算法: 1 求隨機(jī)10個(gè)整數(shù)的最大值、最小值、平均值以及和; Private Sub Command1_Click( Dim i As Integer For i = 1 To 10 List1.AddItem Int(Rnd * 90 + 10 Next End Sub Private Sub Command2_Click( Dim i As Integer, sum As Integer Dim max As Integer, min As Integer max = Val(List1.List(0 min = Va

2、l(List1.List(0 For i = 1 To 9 If max < Val(List1.List(i Then max = Val(List1.List(i If min > Val(List1.List(i Then min = Val(List1.List(i Next Text1.Text = max Text2.Text = min sum = 0 For i = 0 To 9 sum = sum + Val(List1.List(i Next Text4.Text = sum Text3.Text = sum / 10 End Sub 2 求水仙花數(shù); Priv

3、ate Sub Form_Click( Dim p As Integer For n = 100 To 999 a = Int(n / 100 b = Int(n - a * 100 / 10 c = n - (a * 100 + b * 10 p = a 3 + b 3 + c 3 If p = n Then Print p Next n End Sub 3 百元買百雞問(wèn)題; Private Sub Command1_Click( Dim x As Integer, y As Integer, z As Integer List1.AddItem "公雞 母雞 小雞" F

4、or x = 1 To 20 For y = 1 To 33 z = 100 - x - y If 5 * x + 3 * y + z / 3 = 100 Then List1.AddItem CStr(x & Space(4 & CStr(y & Space(4 & CStr(z End If Next y Next x End Sub 4 求1000以內(nèi)的所有完數(shù); Private Sub Command1_Click( Dim i As Integer, j As Integer, s As Integer For i = 0 To 100 s = 0 F

5、or j = 1 To i - 1 If i Mod j = 0 Then s = s + j End If Next If i = s Then List1.AddItem i End If Next End Sub 5 求各位數(shù)字之和; Function f各位數(shù)字之和(x As Integer Dim s As String, ch As String f各位數(shù)字之和 = 0 s = CStr(x For i = 1 To Len(s ch = Mid(s, i, 1 f各位數(shù)字之和 = f各位數(shù)字之和 + Val(ch Next End Function 6 求最小公倍數(shù); Priva

6、te Sub Command1_Click( Print f最小公倍數(shù)(3, 6 End Sub 或:Dim a As Integer, b As Integer a = Val(text1.Text b = Val(text2.Text label1.Caption = CStr(f最小公倍數(shù)(a, b Function f最小公倍數(shù)(x, y As Integer Dim i As Integer For i = x To x * y Step x If i Mod y = 0 Then f最小公倍數(shù) = i Exit For End If Next End Function 7 求逆序數(shù)

7、; Private Sub Command1_Click( Dim s As String, r As String Dim i As Integer, ch As String s = Text1.Text For i = 1 To Len(s ch = Mid(s, i, 1 r = ch & r Next Text2.Text = r End Sub 8 級(jí)數(shù)有限項(xiàng)求和問(wèn)題; Dim i As Integer ,sum As Integer Dim a as Integer, b as integer ,c as integer ,d as integer A=1 B=2 Sum

8、 =0 For i=0 to 10 Sum=sum+a/b*1/(f階乘(i) D=a+b C=b A=c B=d Next End sub Function f階乘(ByVal n As Integer As Boolean Dim I as integer f階乘 = 1 for I = 2 to n f階乘 =f階乘*i next End Function 9 求質(zhì)因子問(wèn)題; Function f素?cái)?shù)(ByVal x As Integer As Boolean Dim i As Integer For i = 2 To x - 1 If x Mod i = 0 Then Exit Fun

9、ction Next f素?cái)?shù) = True End Function 10 字符統(tǒng)計(jì)。 Private Sub Command1_Click( Dim s1(1 To 100 As String, s2(1 To 100 As Integer Dim str As String, i As Integer, n As Integer str = Text1.Text n = 0 For i = 1 To Len(str ch = UCase(Mid(str, i, 1 For j = 1 To 100 If s1(j = ch Then s2(j = s2(j + 1 Exit For End

10、 If Next If j > 100 Then n = n + 1 s1(n = ch s2(n = 1 End If Next For i = 1 To 100 If s2(i > 0 Then List1.AddItem s1(i + ":" + CStr(s2(i End If Next End Sub 第二題要求(25分): 指定編寫過(guò)程并調(diào)用此過(guò)程,覆蓋以下算法: 1判定素?cái)?shù)過(guò)程;(程序有問(wèn)題) Private Sub Command2_Click( Dim x As Integer x = Val(Text1.Text Print f素?cái)?shù)(x En

11、d Sub Function f素?cái)?shù)(x As Integer Dim i As Integer f素?cái)?shù) = true For i = 2 To x - 1 If x Mod i = 0 Then f素?cái)?shù) = False Exit Function End If Next End Function 2 求最大公約數(shù)過(guò)程; Private Sub Command1_Click( Print f最大公約數(shù)(3, 6 End Sub 或:Dim a As Integer, b As Integer a = Val(text1.Text b = Val(text2.Text label1.Captio

12、n = CStr(f最大公約數(shù)(a, b Function f最大公約數(shù)(x, y As Integer Dim i As Integer For i = x To 1 Step -1 If x Mod i = 0 And y Mod i = 0 Then f最大公約數(shù) = i Exit For End If Next End Function 3 冒泡排序過(guò)程; Private Sub Command5_Click( Dim s(1 To 15 As Integer Dim i As Integer For i = 1 To 15 s(i = Int(Rnd * 90 + 10 Next F

13、or i = 1 To 15 Print s(i; Next Print Call s冒泡法(s For i = 1 To 15 Print s(i; Next End Sub Sub s冒泡法(x( As Integer Dim i As Integer, j As String, n As Integer For i = LBound(x To UBound(x n = 0 For j = LBound(x To UBound(x - i If x(j > x(j + 1 Then Call swap(x(j, x(j + 1 n = n + 1 End If Next If n =

14、 0 Then Exit For Next End Sub 4 順序查找過(guò)程; Function f要查找的數(shù)(x( As Integer, ByVal n As Integer As Integer Dim i As Integer f要查找的數(shù) = LBound(x - 1 For i = LBound(x To UBound(x If x(i = n Then f要查找的數(shù) = i Exit Function End If Next End Function 5 判斷回文數(shù)過(guò)程; Private Sub Command4_Click( x = Val(Text1.Text Print f

15、回文數(shù)(x End Sub Function f回文數(shù)(x As Boolean Dim s As Integer, r As String Dim i As Integer, ch As String s = CStr(x r = "" For i = 1 To Len(s ch = Mid(s, i, 1 r = ch & r Next If r = s Then f回文數(shù) = ture 或:f回文數(shù) = (r = s End Function 6 遞歸函數(shù)求階乘; Function f階乘(ByVal n As Integer As Boolean If n

16、<= 1 Then f階乘 = 1 Else f階乘 = n * f階乘(n - 1 End If End Function 7 遞歸函數(shù)求Fibonacci數(shù)列; Function fab(ByVal n As Integer As Long If n = 1 Or n = 2 Then fab = 1 Else fab = fab(n - 1 + fab(n - 2 End If End Function 8 矩陣靠邊元素之和; Function f靠邊矩陣之和(x As Integer f靠邊矩陣之和 = 0 For i = LBound(x, 1 To UBound(x, 1 F

17、or j = LBound(x, 2 To UBound(x, 2 If i = LBound(x, 1 Or i = UBound(x, 1 Or j = LBound(x, 2 Or j = UBound(x, 2 Then f靠邊矩陣之和 = f不靠邊矩陣之和 + x(i, j End If Next Next End Function 9 矩陣不靠邊元素之和; Function f不靠邊矩陣之和(x As Integer f不靠邊矩陣之和 = 0 For i = LBound(x, 1 To UBound(x, 1 For j = LBound(x, 2 To UBound(x, 2 If Not (i = LBound(x, 1 Or i = UBound(x, 1 Or j = LBoun

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論