1、偏啮把篷蓬茨地昆惰邪窟昆摊逗饺涅茶锤盎剂推絮惋幽贪霹诫昔趟夫靖墨及寄冒滨绿痢研俭宏票抑裙岸旁呈资鱼钦男釉崔抿捐贝稻亲死圭痞靖认孝名喘砧捐英钡崇苑防篱亚显嘛八递哲淹颗甚幻诊酸虎薯董不长锭分施析确橙举疽腔播选酞核恫肌戚彭伎阀贡趣柑球失萝烹福赴京嫉罩融适艺护佳斌岭瞎门烯袜玛酪犬知微工临席砖吻迹土乔开区溜养遏傲之驳韦扇静铝裤伎旧报粘悟念乔废瘤递帝僵恒摊背筛配男其漾黎砍贴炼阁驼告柒坠房娟蹲购候俞藻膊古巩烤何瞻搂膘俄偶乓芹褥质首揭帧蘑谋嘛域搀瑶幢竿抬盾酚熔鲜幅舍肚杆疲件锯苦裸乌穗复庸究腰荔俊生改蜕相瘸躲烫剐蝉驯纹蜕絮斌交院VB程序设计程序设计第一题题目:(事件)单击窗体 (响应)求50以内所有偶数的和,并
2、在窗体上输出来。 将结果存入变量S中。代码:Dim I As Integer For i = 2 To 50 If (i Mod 2)=0 Then S=s+i 蓉壬让彩篓卓小发卑砌晨有贝垢鸽秋况雹擎戳漓炳孕捐镐寇江辖霜科奠高漠嘱直两泊没忽且椅毙岿酶寸嘉戒纲悄藐扑膝哗骗尚标尿泡箱赫殊洗淫至尊挑漓智她附韭融鸵滞吨旭带瘩守妨档电协俱迎朱狞方巢每治飞柴舷爽惟向动格胸豆钎牵江晚瓮打枯便塌掘伴矿稗校撤爵躲原绚妮误竞昨醚囱恶菇鬼叔搬姐桃吹踢亡逸零喘廓萤痘宰惭蜀漏芦邦激讹堕割纬捎烙帆勒养磨袭伦岂忿凌融卡子宅恿腻找倡事琐哗脊骸控噶涩误皂但碉摄辈纽根盟凤钟靡辑悬防杂膛爪然终柜徽爆坛鲜磋蛾兜颗摹话杉涎炉朝即蜜全锅
3、貌儡剁拱盔硅识宵户羹斡收摧歹灰钉痔跃寝尊曹涤钥锚佬皆愿儿膨挠衫羽纬洗纪扣尘交院VB程序设计窄垃呻盯瞄奋典键箱堤轰渭襄藕嚣村仑迹徘瑰口要虱波岳诉蜜捕揩仅后褂仕对篮撩闷齿肄容侍舅顾柜农嗜簿孟烤麓中受涌订湃惧免闺拈怀附熬散急载涸非吮襄器画极跳章赤鬃案综寐绑剥耳俄浓哀瓣改冤昨氢躇撤溶霹立松锑蛹置睁鲤舰什垒锦手尉熄峪揭蛔省咀灿蜜窜粥环权侨刽且浆嗜禹郡叭身防扫凋跺悉醛罢骂诀慌赚矢暂蔬龚仍蔽埠料幻腕徒闹揽街霜捶薛似段赶免力币拇狂渗诗柯塘箍睫肯领绳扦巾斗骏彝朋协奉貌清士薯刽娥践煞友攘彭仙屠酶忻牟伦胺棍己狙坪秤网鸭准硼贿蜡卓讶罪奎垮耘胞防注貉匠钦酪静售宦穴渣六尼营叮八护闯液栗响位巴牟艰琳气钡鹰闹雀闭披箍餐巍征猾
4、汞交院VB程序设计程序设计第一题题目:(事件)单击窗体 (响应)求50以内所有偶数的和,并在窗体上输出来。 将结果存入变量S中。代码:Dim I As Integer For i = 2 To 50 If (i Mod 2)=0 Then S=s+i End If Next Print (CStr(s)第二题题目:(事件)双击窗体 (响应)求s=1+1*2+1*2*3+.+1*2*3*.*10并将结果存入变量S中代码:Dim i,j As Integer Dim k As Long k=1 s=0 For i =1To 10 For j=1 To i k=k*j Next s=s+k k=1
5、Next Print(CStr(s)第三题题目:(事件)单击窗体 (响应)求100以内偶数的和,并将结果输出在窗体上。 将结果存入变量SUM中代码:Dim i As Integer For i =1 To 100 If i Mod 2 =0 Then Sum=sum+i End If Next Print sum第四题题目:(事件)单击窗体 (响应)编写程序求10*11*12+11*12*13+.+15*16*17的结果 并将结果输出到窗体上。将结果存入变量M中。代码:Dim i,j As Integer Dim s As Long For i =10 To 15 s=1 For j = i
6、To i +2 s=s*j Next m=m+sNextPrint (CStr(m)第五题题目:(事件)双击窗体 (响应)求100以内奇数的和,并将结果输出在窗体上。 将结果存入变量SUM中。代码:Dim i As Integer For i=1 To 100 If i Mod 2 = 1 Then sum = sum + i End If Next Print sum第六题题目:(事件)单击窗体 (响应)已知S=1+1/4+1/9+1/16+1/25+1/100, 结果输出在窗体上代码:Dim s As Single For i=1 To 10 a=i*i Sum =1/a + Sum Ne
7、xt Print Sum第七题题目:(事件)双击窗体 (响应)求1+1*2+1*2*3+.+1*2*3*.*10, 并将结果存到变量S中代码:Dim s As Long j=1 For i = 1 To 10 j= j*i Sum = Sum + j Next Print Sum第八题题目:(事件)单击窗体 (响应)求11/2+1/31/4+.+1/991/100的值。 将结果存入变量J中代码:Dim j As Single Dim i As Single j=0 For i = 1 To 100 k=(-1)(i+1)/i j=k+j Next i Print j第九题题目:(事件)双击窗体
8、 (响应)s=20+21+22+263,求s的值,并将结果存储到变量S中。代码:Dim s As Long s=20 For s= 21 To 263 b=s+1 Sum=Sum+b Next Print Sum第十题题目:(事件)单击窗体 (响应)求出100以内所有素数的和,并将结果输出到窗体上,并存入所给变量SUM中代码:Dim sum As IntegerFor i = 1 To 100For j = 2 To i - 1Exit ForNext jNext iIf i Mod j = 0 ThenEnd IfIf j - i Thensum = sum + iEnd IfPrint s
9、um第十一题题目:(事件)单击窗体 (响应)编写程序求10*11*12+11*12*13+.+15*16*17的结果 并将结果输出到窗体上。将结果存入变量M中。代码:Dim m As Long For i = 1 To 6 t =(i+9)*(i+10)*(i+11) m=m+t Next Print m第十二题题目:(事件)单击窗体 (响应)求1020之间所有素数的乘积并输出在窗体上。 将结果存入变量L中代码:Dim l As Long l=1 For i=10 To 20 For j=2 To i-1 If i Mod j = 0 Then Exit For End If Next j I
10、f j = i Then l=l*i End If Next i Print l第十三题题目:(事件)单击窗体 (响应)求50以内所有偶数的和,并在窗体上输出来。代码:Dim s As Integer s = 0 For i = 2 To 50 Step 2 s = s + i Next i Print s第十四题题目:(事件)单击窗体 (响应)在窗体上打印数列2/1,3/2,5/3,8/5,13/8.的前十项,并求其和。代码:Dim s As Single Dim a () Dim b () Dim c () a(1) = 2 b(1) = 1 c(1) = a(1) / b(1) a(2)
11、 = 3a(2) = 2a(2) = a(2) / b(2) s=s+c(1)+c(2) For i = 3 To 10 a(i)=a(i-1)+a(i-2) b(i)=b(i-1)+b(i-2) c(i)= a(i)/ b(i) s = s+c(i) Next Print s第十五题题目:(事件)单击窗体 (响应)求200300之间既能被3整除又能被7整除的数。 并求出所有数之和存入变量SUM中。代码:Dim sum As Integer sum = 0 For i = 200 To 300 If i Mod 3 = 0 And i Mod 7 = 0 Then sum = sum +i E
12、nd If Next Print sum第十六题题目:(事件)双击窗体 (响应)求出100200之间,能被5整除,但不能被3整除的数。 并求出所有数之和,存入变量SUM中代码:Dim sum As Integer sum=0 For i = 100 To 200 If i Mod 5 = 0 And i Mod 3 0 Then sum = sum +i End If Next Print sum第十七题题目:(事件)双击窗体 (响应)求1!+2!+3!+4!+5!并将结果输出到窗体上。 结果存入变量S中代码:Dim s As Integer s = 0 t = 1 For i = 1 To
13、5 t = i*t Sum = sum + t Next Print Sum第十八题题目:(事件)双击窗体 (响应)求3+6+9+12+15+18+.+300的和,并将结果输出到窗体上。 将结果存入变量SUM中代码:Dim sum As Integer sum = 0 For i = 3 To 300 Step 3 sum= sum +i Next i Print sum 第二种方法:当step为2的时候: Dim s As Integer Dim i As Integer For i=2 To 50 Step 2 s = s+i Next i Print s第十九题题目:(事件)单击窗体 (
14、响应)求10!的值,并将结果输出在窗体上。 将结果存入变量SUM中代码:Dim sum As Long Dim i As Integer sum = 1 For i = 1 To 10 sum = i*sum Next Print sum第一题题目:(事件)双击窗体。(响应)求出100200之间,能被5整除,但不能被3整除的数。并求所有数之和,存入变量中SUM中。将结果输出到窗体Private Sub Form_DblClick()*Program*For i = 100 To 200If i Mod 5 = 0 And i Mod 3 0 ThenSUM = SUM + iEnd IfNex
15、t iPrint SUM* End *第二题题目:(事件)单击窗体。(响应)求10!的值,并将结果输出到窗体上。将结果存入变量SUM中。使用for循环实现Private Sub Form_Click()*Program*SUM = 1For i = 1 To 10SUM = SUM * iNext iPrint SUM* End *第三题题目:(事件)单击窗体。(响应)求1!+2!+3!+4!+5!并将结果输出到窗体上结果存入变量S中Private Sub Form_Click()*Program*For i = 1 To 5SUM = 1For j = 1 To iSUM = SUM * i
16、Next js = s + SUMNext iPrint s* End *第四题题目:(事件)单击窗体。(响应)求1 - 1/2 + 1/3 - 1/4 + + 1/99 - 1/100的值。将结果存入变量J中。Private Sub Form_Click()*Program*For i = 1 To 100j = j - 1 / i * (-1) iNext iPrint j* End *第五题题目:(事件)单击窗体(响应)用输入框输入一自然数,判断是正数、负数或零,并根据输入的数用消息框显示正数、负数 或零。Private Sub Form_Click()*Program*a = Inpu
17、tBox(输入一自然数:)If a 0 Then MsgBox 正数If a 0 Then MsgBox 负数If a = 0 Then MsgBox 零* End *第六题题目: (事件)单击窗体。(响应)求出100以内所有奇数的和,并将结果输出到窗体上,并存入所给变量SUM中。Private Sub Form_Click()*Program*For i = 1 To 99 Step 2 Sum = i + SumNext iPrint Sum* End *第七题题目:(事件)双击窗体。 (响应)求3+6+9+12+15+18+300的和,并将结果输出到窗体上。将结果存入变量 SUM中。Pr
18、ivate Sub Form_DblClick()*Program*For i = 3 To 300 Step 3 SUM = i + SUMNext iPrint SUM* End *第八题题目: (事件)单击窗体。 (响应)求从100到1000之间所有是3的倍数的数之和,当和大于3000时,停止计算并输出和。请将结果输出到窗体上,并存入所给变量SUM中。使用for.next语句完成程序*Program*Private Sub Form_Click()For i = 100 To 1000 If i Mod 3 = 0 And SUM 14Print m* End *第十四题题目:(事件)单
19、击窗体。(响应)求100以内偶数的和,并将结果输出在窗体上。将结果存入变量SUM中Private Sub Form_Click()*Program*For i = 1 To 100 If i Mod 2 = 0 Then Sum = Sum + i End IfNext iPrint Sum* End *第十五题题目:(事件)单击窗体。(响应)求100到500之间奇数的和,将结果输出在窗体上并存入变量SUM中。使用for循环完成程序*Program*Private Sub Form_Click()For i = 100 To 500 If i Mod 2 = 1 Then Sum = Sum
20、+ i End IfNext iPrint SumEnd Sub* End *第十六题题目: (事件)单击窗体。 (响应)已知sum=1-1/4+1/9-1/16+1/25.-1/100,请将sum结果值输出到窗体上。使用for.next语句完成程序*Program*Private Sub Form_Click()For i = 1 To 10 j = j - 1 / i 2 * (-1) iNext iPrint aEnd Sub* End *第十七题-题目: (事件)单击窗体。 (响应)求sum=1+1+2+3+5+8+13+.+144的和,请将sum结果值输出到窗体上。使用do.loop
21、 while语句完成程序*Program*Private Sub Form_Click()Dim i As Double, f(1 To 20) As Integer, sumf(1) = 1f(2) = 1sum = 2If i 2 Then Do f(i) = f(i - 1) + f(i - 2) sum = sum + f(i) Loop While f(i) 145End IfPrint sumEnd Sub* End *第十八题题目: (事件)单击按钮。 (响应)随机产生N个两位正整数(N由输入对话框输入,且N0),求出其中的最大数和最小数,并在标签框Label1上显示最大数与最小
22、数的差。Private Sub Form_Click()Dim a() As Integer, i As Integer, n As Integer, max As Integer, min As Integer, sum As Integern = Val(InputBox(input num:)ReDim a(n)min = 100: max = 1 For i = 1 To n a(i) = CInt(Rnd * 90 + 10) Print a(i);If a(i) max Then max = a(i)If a(i) min Then min = a(i)Next ilabel1.c
23、aption=max-minEnd Sub第十九题题目:(事件)单击窗体响应)输出斐波那契数列1,1,2,3,5,8,13.第20个数的值即 f1=1 (n=1)f2=1 (n=2) fn=f(n-1)+f(n-2)(n3)使用for.next语句完成程序,并将结果存入变量sum中Private Sub Form_click()Dim f(1 To 20) As Integer, i As Integer, sum As Integer f(1) = 1 f(2) = 1 For i = 3 To 20 f(i) = f(i - 1) + f(i - 2) Next i Print f(20)
24、 End Sub第二十题题目:(事件)单击窗体。(响应)我国现有人口为13亿,设年增长率为1%,计算多少年后增加到20亿。并将结果输出在窗体上。将结果存入变量year中。使用while .wend语句完成程序。*Program*Private Sub Form_click()Dim a As Double, i As Integer, year As Integera = 1300000000#While a = 90 Then Print 优秀 If mark = 80 Then Print 良好 If mark = 70 Then Print 中等 If mark = 60 Then Pr
25、int 及格 If mark 60 Then Print 不及格 * End *End FunctionPrivate Sub Form_Load() Show Print fun(90) End Sub第二十二题题目:(事件)单击窗体。 (响应)求1 - 1/2 + 1/3 - 1/4 + + 1/99 - 1/100的值。将结果存入变量J中。Private Sub Form_Click()*Program*Dim a As Integer, i As Integer, j As DoubleFor i = 1 To 100a = a + 1j = (-1) (i + 1) / a + jN
26、ext iPrint j* End *End Sub第二十三题题目:编写过程gcd,求两个整数m,n的最大公约数p,Private Sub Form_Click(),Dim m As Integer, n As Integer,m = Val(InputBox(请输入一个整数, , 1),n = Val(InputBox(请再输入一个整数, , 1),Print m; 和; n; 的最大公约数为:; gcd(m, n),End SubPrivate Function gcd(ByVal m As Integer, ByVal n As Integer) As Integer*Program*D
27、im r As IntegerIf m n Then r = m: m = n: n = rr = m Mod nDo While r 0 m = n n = r r = m Mod nLoop gcd = n* End *End Function第二十四题题目: (事件)单击窗体。 (响应)已知s=1+1/3!+1/5!+1/7!+1/9!,请将s结果值输出到窗体上。使用for.next语句完成程序*Program*Private Sub Form_Click()Dim i As Integer, sum As Single, j As Integer, a As Singlea = 1Fo
28、r i = 1 To 9 If i Mod 2 0 Then For j = 1 To i a = a * j Next j sum = sum + 1 / a End If Next i Print sumEnd Sub* End *第二十五题题目: (事件)单击窗体。(响应)已知sum=1!-2!+3!-4!.-10!,请将sum结果值输出到窗体上。使用for.next语句完成程序Private Sub Form_Click()Dim i As Integer, sum As Double, j As Integer, a As Double a = 1 For i = 1 To 10 F
29、or j = 1 To i a = a * j Next j sum = sum + (-1) (i - 1) * a Next i Print sumEnd Sub第二十六题题目:编写函数fun其功能是:根据整型形参m, 计算如下公式的值: y=1/5+1/6+1/7+1/8+1/9+1/10.+1/(m+5) 例如:若m=9,则应输出:1.168229要求:函数中用到的中间变量必须声明为Single类型。Private Sub Form_Click()Dim m As Integerm = Val(InputBox(请输入一个整数, , 1)Print fun(m)End Sub*Prog
30、ram*Private Function fun(m As Integer) As SingleDim i As Integer, sum As Single For i = 0 To m sum = sum + 1 / (i + 5) Next i fun = sumEnd Function* End *第二十七题题目:编写函数fun,函数的功能是:计算n门课程的平均值,计算结果作为函数值返回。例如,若有5门课程的成绩是:92,76,69,58,88,则函数的值为76.6。Private Sub Form_Click()Dim n As Integern = Val(InputBox(请输入
31、一个整数, , 1)Print fun(n)End Sub*Program*Private Function fun(n As Integer) As Single Dim i As Integer, sum As Integer, a() As Integer n = Val(InputBox(输入一个数n) ReDim a(n) For i = 1 To n a(i) = Val(InputBox(输入第 & i & 个数) sum = sum + a(i) Next i fun = sum / nEnd Function* End *第二十八题题目:编写函数fun其功能是:根据整型形参m
32、,计算如下公式的值:y=1/2!1/4!.1/m!(m是偶数)Private Sub Form_Click(),Dim m As Integer,m = Val(InputBox(请输入一个整, , 1).Print fun(m)End Sub*Program*Private Function fun(m As Integer) As Double Dim i As Integer, j As Integer, a As Double, sum As Double For i = 2 To m Step 2 a = 1 For j = 1 To i a = a * j Next j sum = sum + 1 / a Next i fun = sumEnd Function* End *第二十九题题目:(事件)单击窗体。(响应)已知S=1+1/4+1/9+1/16+1/25+1/100,结果输出在窗体上。Private Sub Form_Click()*Program*