VB程序改错题.doc
《VB程序改错题.doc》由会员分享,可在线阅读,更多相关《VB程序改错题.doc(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-作者xxxx-日期xxxxVB程序改错题【精品文档】程序改错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
2、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 Su
3、b3.题目:本程序的功能是随机产生的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(
4、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 =
5、 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 ExplicitPriv
6、ate 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。
7、当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)
8、 / 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
9、 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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 程序 改错
限制150内