VB程序改错题.doc_第1页
VB程序改错题.doc_第2页
VB程序改错题.doc_第3页
VB程序改错题.doc_第4页
VB程序改错题.doc_第5页
免费预览已结束,剩余7页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

程序改错1.题目:已知C的公式表示如下: n! C=- (n-m)!*m! 函数过程fac( )求k!函数,在Fomr_Click事件中完成运算,请修正程序中错误。-Option ExplicitPrivate Function fac(k As Integer) As Single Dim x As Single, j As Integer x = 0 For j = 1 To k x = x j Next j fac = xEnd FunctionPrivate Sub Form_Click() Dim C As Single Dim m As Integer, n As Integer m = Val(InputBox(请输入一个整数(m):) n = Val(InputBox(请输入一个整数(n):) C = fac(n) / fac(n - m) * fac(m) Print C=; CEnd Sub2.题目:程序功能为打印下列图形: * * * * *-Option ExplicitPrivate Sub Form_Click()ClsDim i As IntegerDim j As IntegerFor i = 1 To 7 For j = 1 To 5 Print *; LoopPrintNext iEnd Sub3.题目:本程序的功能是随机产生的10个两位正整数,并进行递减排序。-Option ExplicitPrivate Sub CreateRND() Dim Temp As Integer Dim I As Integer Dim N As Integer Dim X(10) As Integer Dim J As Integer N = 10 Print 数据: For I = 1 To N X(I) = Int(Rnd() * 90) Print X(I); Next I Print Print 排序: For I = 0 To N - 1 For J = I + 1 To N If X(I) X(J) Then Temp = X(I) X(J) = X(I) X(I) = Temp End If Next J Print X(I); Next I PrintEnd SubPrivate Sub Command1_Click() CreateRNDEnd Sub4.题目:随机产生并输出100以内大于50的20个整数,输出时每5个数一行。-Option ExplicitPrivate Sub Form_Click()Randomize TimerDim i As Integer, ma As Integeri = 1Do Until i 50 Then Print ma; i = i + 1If i 5 = 0 ThenPrint End IfEnd IfLoopEnd Sub5题目:以下程序段用于计算5的N次方。-Option ExplicitPrivate Sub Form_Click() Dim n As Integer, k As Integer, s As Long n = InputBox( Input n ) k = 0 s = 0 Do While k = n s = s * 5 k = k + 1 Next Print 5的; n次方是; sEnd Sub6.题目:下面程序可输出如下图形: * * * * *- Option ExplicitPrivate Sub Form_Click()Dim m As Integer, n As Integer, s As String, i As Integer, j As Integern = 4m = 1s = *For i = 5 To 1 Step -1 Print Spc(n) For j = 1 To 2 * m - 1 Print s; Next j Print n = n + 1 m = m - 1Next iEnd Sub7.题目:用自定义函数的方法求sum(x),求当-1x1时, sum(x)=x/2!+x2/3!+x3/4!+xn/(n+1)!, 当x1或x-1时,函数值为0。当n=0时,输入数 据错误。X、N都是由用户输入。-Option ExplicitPrivate Sub Command1_Click() Dim s As Single Dim n As Integer, x As Single, k As Integer n = Val(InputBox(Please input a integer value:) x = Val(InputBox(Please input a single value:) If n 1 Or x -1 Then Exit Do Else For i = 2 To n ss = ss * i Sum = x (i - 1) / ss Next i End IfEnd Function8.题目:以下程序功能是输入三个数,由大到小排序。-Option ExplicitDim A As IntegerDim B As IntegerDim C As IntegerPrivate Sub Form_Click() Dim nTemp As Integer A = Val(InputBox(Please input first integer, 输入正整数) B = Val(InputBox(Please input second integer, 输入正整数) C = Val(InputBox(Please input third integer, 输入正整数) If A = C Then nTemp = A A = B B = nTemp End If If B = C Then nTemp = A A = C C = nTemp End If If A = B Then nTemp = B B = C C = nTemp End If Print The integers in order is; A; B; CEnd Sub9.题目:用辗转相除法求两个整数的最大公约数。-Option ExplicitFunction gcd(ByVal m As Integer, ByVal n As Integer) As Integer Dim r As Integer r = m Mod n Do While r 0 n = m n = r r = m Mod n Loop gcd = rEnd FunctionPrivate Sub Form_Click() Dim a As Integer, b As Integer, c As Integer a = InputBox(输入一个整数) b = InputBox(输入一个整数) a = Val(a) b = Val(b) Call gcd(a, b) Print a, b, cEnd Sub10.题目:下面的程序用“冒泡”法完成数组a中的10个整数按升序排列,请修正程序中错误。-Option ExplicitPrivate Sub Command1_Click() Dim a Dim i As Integer, j As Integer, a1 As Integer a = Array(-2, 5, 24, 58, 43, -10, 87, 75, 27, 83) For i = 1 To 9 For j = i+1 To 9 If a(j) = a(i) Then a1 = a(i a(i) = a(j) a(j) = a(i) End If Next j Next i For i = 0 To 9 Print a(i) Next iEnd Sub11.题目:程序功能为求解一元二次方程的实根,请修正程序中错误。-Option ExplicitPrivate Sub Form_Load() Dim a!, b!, c!, root1#, root2#, work As Double a = Val(InputBox( 请输入系数a的值) b = Val(InputBox( 请输入系数b的值) c = Val(InputBox( 请输入系数c的值) work = b * 2 - 4 * a * c If work = 0 And a 0 Then root1 = (Sqr(work) / (2 * a) root2 = (Sqr(work) / (2 * a) Debug.Print 有二个实根 + Str$(root1) + , + Str$(root2) Else Debug.Print 无实根! End IfEnd Sub12.题目:下面程序的作用是产生100以内的全部素数,并按每行5个数据输出。-Option ExplicitPrivate Function prime(ByVal n As Integer) Dim i As Integer prime = 1 If n 3000Print 从1 到:; i; 的和是; sEnd Sub15.题目:以下程序段用于输出100-300的所有素数-Option ExplicitPrivate Sub Form_Click()Dim n As Integer, k As Integer, i As Integer, swit As IntegerFor n = 101 To 300 Step 2 k = Int(Sqr(n) i = 2swit = 1While swit = 0 If n Mod i = 0 Then swit = 1 Else i = i - 1 End If WendIf swit = 0 Then Print n;End IfNext nEnd Sub16.题目:本程序的功能是随机产生的10个两位正整数,并进行递减排序。-Option ExplicitPrivate Sub CreateRND() Dim Temp As Integer Dim I As Integer Dim N As Integer Dim X(10) As Integer Dim J As Integer N = 10 Print 数据: For I = 1 To N X(I) = Int(Rnd() * 90) Print X(I); Next I Print Print 排序: For I = 0 To N - 1 For J = I + 1 To N If X(I) X(J) Then Temp = X(I) X(J) = X(I) X(I) = Temp End If Next J Print X(I); Next I PrintEnd SubPrivate Sub Command1_Click() CreateRNDEnd Sub17.题目:输入两个正整数m和n,求其最大公约数。-Option ExplicitPrivate Sub Form_Click() Dim m As Integer, n As Integer, r As Integer m = InputBox(输入m的值:) n = InputBox(输入n的值:) Do While n 0 r = m / n m = n n = m r Loop Print 两数的最大公因子为:; nEnd Sub18题目:下面程序将10个整数从大到小排序-Option ExplicitPrivate Sub Form_Click()Dim t%, m%, n%, w%Dim a(10) As IntegerFor m = 1 To 10 a(m) = Int(10 + Rnd() * 90) Print a(m); ;Next mPrintFor m = 1 To 9 t = m For n = 2 n+1 To 10 If a(t) a(n) Then n = t Next n If t = m Then w = a(m) a(m) = a(t) a(t) = w End IfNext mFor m = 1 To 10 Print a(m)Next mEnd Sub19.题目:求s=72+102+132+832的值。-Option ExplicitPrivate Sub Form_Click()ClsDim s As LongDim i As Integers = 1For i = 7 To 832s = s + iloop 30Print sEnd Sub20.题目:下面程序用于将十个数字从小到大排序-Option ExplicitOption Base 1Private Sub Form_Click()ClsDim a(10) As In

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论