《VB二级期末考试VB二级实验考题课件.docx》由会员分享,可在线阅读,更多相关《VB二级期末考试VB二级实验考题课件.docx(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、VB1 .求一个四位数的各位数字的立方和。Private Function fun(n As Integer) as longDim d as integer, I as integer, s as integerFor i = 1 to 4d = val ( mid (n,I,l)s = s+dA3Next iFun = sEnd function.求1到100之间的偶数之积。Private Function fun(m As Integer) as doubleDim y as double , i as integery= 1m=100For i =1 to mif i mod 2 =
2、0 Theny = y* 1End ifNextFun = yEnd function.计算n门课程的平均值,计算结果作为函数值返回。Private Function fun(a() As Integer,! as integer ) as doubleDim i as integer , y as singleFor i = 1 to ny = y + a(i)Nextfun = y / nEnd function.计算0到100范围内所有偶数的平方和。Private sub command l_click()d = fun ()Text 1.text = dSave DataEnd sub
3、Function fun()Sum = 0For i =0 to 100 step 2Sum = sum + i * INext I fun=sumEnd function2 .计算输出给定整数n的所有因子之和(不包括1马自身),规定n的值不大于1000。Private function fun (n as integer ) as integerDim s as integer , i as integerFor i = 2 to n -1If n mod i = 0 thenEnd ifNextfun = sEnd function.判断一个数是否是素数的函数primePrivate Fu
4、nction prime (n As Integer) As BooleanDim i As IntegerIf n =1 then exit functionFori = 2Ton-lIf n Mod i= 0 Then Exit ForNext iIf i = n Then Prime = TrueEnd Function.将字符串逆序的函数resersePrivate function reverse(n as string ) as stringDim i as integerFor i = 1 to len(n)Reverse = mid(n,I,l)&reverseNext iEn
5、d function.求两个数最大公约数的函数gedPrivate function gcd(m as integer, n as integer) as integerDim r as integerDo r = m mod nm = nn = rLoop while r 0ged = mEnd function3 .求n!的值的函数factPrivate Function fact (n as integer) As longDim i As Integerfact - 1For i = 1 To nfact = fact * iNext iEnd Function.求一维数组元素之和的过程。Private function total(a() as integer) as integerDim i as integerFor I = LBound(a) to UBound(a)Total = total + a(i)Next iEnd functon