VB練習(xí)題a及答案.doc_第1頁
VB練習(xí)題a及答案.doc_第2頁
VB練習(xí)題a及答案.doc_第3頁
VB練習(xí)題a及答案.doc_第4頁
VB練習(xí)題a及答案.doc_第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

A1. 編寫程序,計(jì)算并輸出下面數(shù)列前n項(xiàng)的和 (設(shè)n=15,結(jié)果取4位小數(shù))。 數(shù)列為: 2/1,3/2,5/3,8/5,13/8,21/13,(結(jié)果:24.5701)main: Dim a, b, t, I As Integer Dim sum, q As Single a = 1 : b = 2 : sum = 0 For I = 1 To 15 q = b / a sum = sum + q t = a a = b b = b + t Next I sum = Format(sum, #.0000) MsgBox(Str(sum)A2. 編寫程序,計(jì)算并輸出所有六位正整數(shù)中同時(shí)能被3和7整除的數(shù)的個(gè)數(shù)及它們的平方根的和。(結(jié)果:個(gè)數(shù):42858 平方根和:30742714.4533428)Main:Dim n, I As Integer Dim s As Double n = 0 : s = 0 For I = 100000 To 999999 If I Mod 3 = 0 And I Mod 7 = 0 Then n = n + 1 s = s + Math.Sqrt(I) End If Next I MsgBox(個(gè)數(shù)是 + Str(n) + Chr(10) + 平方根之和是 + Str(s)A3. 編寫程序,計(jì)算并輸出所有6位正整數(shù)中能被6整除且其十位數(shù)不是4的數(shù)之和,并求它們中的最大數(shù)。 (結(jié)果:和:7.42508E+10 最大值:999996)Main: Dim I, max As Long Dim s As Single max = 100000 For I = 100000 To 999999 If (I Mod 6) = 0 And (I Mod 100) 10) 4 Then s = s + I If (max eps) And (I 100) I = I + 1 迭代次數(shù)統(tǒng)計(jì) x1 = x2 將上次計(jì)算結(jié)果作為本次計(jì)算的初值 x2 = 2.5 - Math.Log(x1) End While If I eps) And (I 100) I = I + 1 迭代次數(shù)統(tǒng)計(jì) x1 = x2 將上次計(jì)算結(jié)果作為本次計(jì)算的初值 x2 = 2.5 + Math.Log(x1) End While If I 100 Then MsgBox(函數(shù)根: + Str(x2) + 迭代 + Str(I) + 次) Else MsgBox(已迭代了100次,沒有達(dá)到精度要求!) End If End SubA12 編寫程序,計(jì)算并輸出下面級數(shù)前n項(xiàng)(n=49)中奇數(shù)項(xiàng)的和。 s = 1*2+2*3+3*4+4*5+n*(n+1)+(結(jié)果:21450)Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim n as integer, s as doubles = 0For n = 1 To 49 Step 2 s = s + n * (n + 1)Next nMsgbox(前50項(xiàng)中偶數(shù)項(xiàng)和S=&s)End SubA13編寫程序,計(jì)算并輸出所有5位正整數(shù)中能被7整除且其十位數(shù)不是7的數(shù)之和,并求它們中的最大數(shù)。 (和:6.364356E+08 最大值:99995)Dim I, max As Long Dim s As Single s = 0 max = 10000 For I = 10000 To 99999 If (I Mod 7 = 0) And (I Mod 100) 10 7) Then s = s + I If (max eps) And (Math.Abs(a - b) eps) If F(c) * F(b) 0 Then a = c If F(a) * F(c) eps) And (I 100) I = I + 1 x1 = x2 x2 = 2.5 (-x1) End While If I eps) And (I 100) I = I + 1 x1 = x2 x2 = 1.5 * Math.Sin(x1) End While If I eps) And (i 100) i = i + 1 迭代次數(shù)的統(tǒng)計(jì) x1 = x2 將上次運(yùn)算結(jié)果作為本次計(jì)算的初值 x2 = x1 - f(x1) / f1(x1) End While If i eps) And (Math.Abs(a - b) eps) If F(c) * F(b) 0 Then a = c If F(a) * F(c) 0 Then b = c c = (a + b) / 2 End While MsgBox(函數(shù)根為: + Str(c) + Chr(10) + 該點(diǎn)的函數(shù)值為 + Str(F(c) End SubA21 編寫程序,統(tǒng)計(jì)10000到40000之間回文數(shù)的個(gè)數(shù)。(例:23732即為回文數(shù),即正反讀數(shù)據(jù)相同)(結(jié)果:300)Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, j, p As Integer Dim a, b, c, d, f As Integer Dim str1 As String p = 0 str1 = For i = 10000 To 40000 a = i Mod 10 b = (i Mod 100) 10 c = (i Mod 1000) 100 d = (i Mod 10000) 1000 f = i 10000 j = a * 10000 + b * 1000 + c * 100 + d * 10 + f If i = j Then str1 = str1 + Str(i) + Space(3) p = p + 1 If p Mod 12 = 0 Then str1 = str1 + Chr(10) + Chr(13) End If Next MsgBox(p) End SubA22 編寫程序,求5664,144的最大公約數(shù)(48)Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim num1 As Integer Dim num2 As Integer Dim inlarge As Integer Dim insmall As Integer Dim inrem As Integer num1 = 5664 num2 = 148 If num1 num2 Then inlarge = num2 insmall = num1 Else inlarge = num1 insmall = num2 End If inrem = inlarge Mod insmall While inrem 0 inlarge = insmall insmall = inrem inrem = inlarge Mod insmall End While Label6.Text = Label3.Text + 和 + Label5.Text + 的最大公約數(shù)為: Label7.Text = Str(insmall) End SubA23從三位奇數(shù)中找出其值恰好等于該數(shù)每位數(shù)字立方和的各個(gè)數(shù)之和。(結(jié)果:931)Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, m, n, k As Integer Dim s As integer s = 0 For i = 101 To 999 Step 2 m = i 100 n = (i Mod 100) 10 k = i Mod 10 If (i = m * m * m + n * n * n + k * k * k) Then s = s + i End If Next MsgBox(str(s)End SubA24從三位偶數(shù)中找出其值恰好等于該數(shù)每位數(shù)字立方和的各個(gè)數(shù)之積。(結(jié)果:370)Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, m, n, k As Integer Dim s As integer s = 1 For i = 100 To 998 Step 2 m = i 100 n = (i Mod 100) 10 k = i Mod 10 If (i = m * m * m + n * n * n + k * k * k) Then s = s * i End If Next MsgBox(str(s)End SubA25 編寫程序,用牛頓切線法求方程f(x)=2x3-8x2+15=0(其中表示冪運(yùn)算),在區(qū)間(0,3)上的近似實(shí)根r,迭代初值取1,精確到0.0001。提示:牛頓切線法的計(jì)算公式為x=x-f(x)/f(x)。(結(jié)果:1.88159488)Function f(ByVal x#) As Double f = 2 * x * x * x - 8 * x * x + 15 End Function Function f1(ByVal x#) As Double f1 = 6 * x * x - 16 * x End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x1, x2, eps As Double Dim i As Integer i = 1 x1 = 1 eps = 0.0001 x2 = x1 - f(x1) / f1(x1) While (Math.Abs(x1 - x2) eps) And (i 100) i = i + 1 x1 = x2 x2 = x1 - f(x1) / f1(x1) End While If i eps) And (i 100) i = i + 1 x1 = x2 x2 = x1 - f(x1) / f1(x1) End While If i eps) And (i 100) i = i + 1 x1 = x2 x2 = f(x1) End While If i eps) And (i 100)i = i + 1 x1 = x2 x2 = x1 - f(x1) / f1(x1) End While If i 100 Then MsgBox(函數(shù)根為: + Str(x2) Else MsgBox(已迭代了100次,沒有達(dá)到精度要求!) End If End SubA30 編寫程序,用牛頓切線法求方程f(x)=x3+4x2-10=0(其中表示冪運(yùn)算),在區(qū)間(0,5)上的近似實(shí)根r,迭代初值1,精確到0.0001。提示:牛頓切線法的計(jì)算公式為x=x-f(x)/f(x)。 (1.36523)Function f(ByVal x As Double) As Double f = x 3

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論