资源描述:
《VB编程程序代码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实用标准文档 VB编程程序代码 1、求100以内的素Private Sub Form_Click()Dim i%, j%For i = 2 To 100For j = 2 To i - 1 If i Mod j = 0 Then Exit For Next j If j = i Then Print iNext iEnd Sub2、从键盘输入任意长度的字符串,要求将字符顺序倒置例如,将输入的“ABCDEFG”变换成“GFEDCBA”。Private Sub Command1_Click()Dim a$, I%, c$, d$, n%a = InputBox$("
2、输入字符串")n = Len(a)For I = 1 To Int(n 2) c = Mid(a, I, 1) Mid(a, I, 1) = Mid(a, n - I + 1, 1) Mid(a, n - I + 1, 1) = c Next I Print a End Sub3、计算0~200之间所有能被11或5整除的数之和Private Sub Form_Click()Dim n%, i%文案大全实用标准文档n = 0 For i = 1 To 200 If i Mod 11 = 0 Or i Mod 5 = 0 Then n =
3、 n + i End If Next i Print nEnd Sub4、输入一年份,判断它是否为闰年,并显示有关信息。(判断闰年的条件是:年份能被4整除但不能被100整除,或者能被400整除)Private Sub Command1_Click()Dim y%y = InputBox("请输入年数")If y Mod 4 = 0 And y Mod 100 <> 0 Or y Mod 400 = 0 Then MsgBox (y & "年是闰年")Else MsgBox (y & "年是平年")End IfEnd Sub5、已知x,y,z 3个变量中存放了3个不
4、同的数,比较它们的大小并进行调整,使得x y Then t = x: x = y: y = tIf x > z Then t = x: x = z: z = tIf y > z Then t = y: y = z: z = t文案大全实用标准文档Print "排序后"; x; " "
5、; y; " "; zEnd Sub6、求s=a+aa+aaa+...aaaaa(n个a),其中a和n的值随机产生,a的范围是[1,9]的整数,n的范围是[5,10]。如a=3,n=6,则s=3+33+333+3333+33333+333333。编程确定n和a的值,并计算s。Private Sub Form_Click() Dim s!, t!, i!, a%, n% a = Int(Rnd * 9 + 1) n = Int(Rnd * 6 + 5) t = 0: s = 0 Print "a="; a, "n="; n For i = 1 To
6、n t = t * 10 + a s = s + t Print t; Next i Print Print "s="; s End Sub7、计算100~300之间所有能被3和7整除的数之和。Private Sub Form_Click()For i = 100 To 300If i Mod 21 = 0 Thens = s + iPrint i;End IfNext iPrintPrint "s="; sEnd Sub文案大全实用标准文档8、编程求200--400范围内5的倍数或7的倍数之和。(一个数如果同时是7和5的倍数,
7、则只能加一次。)Private Sub Command1_Click() Dim s1%,s2%,s3%,i% S1=0S2=0For i=200 to 400If i mod 5 =0 or i mod 7=0 then s1=s1+iEnd ifNext i For i=200 to 400If i mod 5 =0 or i mod 7=0 then s2=s2+iEnd ifNext iS3=s1-s2Print s3End sub9、找出被3、5、7除,余数为1的最小的5个正整数。Pr