5.设a=1,b=2,c=3,语句 Print a < b Or b < c And c < a的输出结果是 【5】 。答案:True 6.在窗体上放置一个标签,名称为Label1,使用语句 【6】 可以把标签的前景色设置为蓝色。 = vbBlue 或 RGB(0,0,255) 或QBColor(9) 7.在窗体上放置一个图像框,名称为Image1,要使该图像框向下移动10个默认单位(twip),正确的语句是 = 【7】 答案: + 10 8.使用“菜单编辑器”建立了一个主菜单,名称为menu1。要把它作为窗体Form1的快捷菜单(也称为弹出式菜单)弹出,使用的语句是: 答案:PopupmenuForm1. 【8】 menu1
9.在窗体上放置一个通用对话框控件,名称为CommonDialog1。使用该控件建立“打开”文件对话框时,要求只能显示文本文件(即扩展名为“.txt”的文件),则正确的设置语句是CommonDialog1. 【9】 =\"文本文件(*.txt)|*.txt\"。 答案:Filter
10.设磁盘上已存在顺序文件“”,为了从文件中顺序读取数据而打开该文件,正确的语
句是 Open \"\" For 【10】 As #1。 答案:Input
1.下列面程序运行后,单击窗体,输出结果是 【1】 。答案:1 3 9
Private Sub Form_Click() s = 0
For n=1 To 3 p = 1
For k = 1 To n p = p * k Next k s = s + p Print s; Next n End Sub
2.下列程序运行后,单击窗体,输出结果是 【2】 。答案:7
Private Sub Form_Click() m = 0
For k = 1 To 4 Select Case k Case 1, 2 m = m + 1 Case Is > 3 m = m + 2 Case 1 To 4 m = m + 3 End Select Next k Print m End Sub
3.在窗体上放置一个文本框,名称为Text1。下列程序运行后,单击窗体,Text1中显示的
内容是 【3】 。 答案:ade Private Sub Form_Click() = \"\"
s = \"aBd12Re\" For k = 1 To Len(s) ch = Mid(s, k, 1)
If ch >= \"a\" And ch <= \"z\" Then = + ch End If Next k End Sub 4.下列程序运行后,单击窗体,输出结果是 【4】 。 答案:11 24
Option Base 1
Private Sub Form_Click()
x = Array(3, 5, 4, 8, 2, 6, 11, 9, 7, 4) p = x(1): s=0
For k = 2 To UBound(x) If x(k) > p Then p = x(k)
s = s + p End If Next k Print p; s End Sub
5.下列程序运行后,单击窗体,输出结果是 【5】 。 答案:1 5 1
Private Sub Form_Click() Dim a(1 To 3, 1 To 3) For i = 1 To 3 For k = 1 To 3
If k = 1 Or i = k Then a(i, k) = 1 Else
a(i, k) = i + k End If Next k Next i
Print a(1, 1); a(2, 3); a(3, 3) End Sub 6.在窗体上放置一个命令按钮,名称为Command2,并编写如下代码。
Private Sub Command2_Click()
Dim m As Integer, n As Integer, g As Integer m = 18: n = 12: g = 0 Call sub1(m, n, g) Print m; n; g End Sub
Public Sub sub1(ByVal a As Integer, ByVal b As Integer, c As Integer) If a < b Then t = a: a = b: b = t Do While b <> 0 r = a Mod b a = b b = r Loop c = a End Sub
程序运行后,单击命令按钮,则输出结果是 【6】 。答案:18 12 6 7.在窗体上放置一个命令按钮,名称为Command3,并编写如下代码。
Private Sub Command3_Click() Dim k As Integer k = 1
Print fun1(k); Print fun1(k); Print fun1(k); End Sub
Function fun1(a As Integer) As Integer Static c As Integer Dim b As Integer
a = a + 2: b = b + 2: c = c + 2 fun1 = a + b + c End Function
程序运行后,单击命令按钮,则输出结果是 【7】 。答案:7 11 15 8.在窗体上放置一个文本框,其名称为Text1,并编写如下代码。
Dim s As String
Private Sub Text1_KeyPress(KeyAscii As Integer) s = s + Chr(KeyAscii) Print s; End Sub
程序运行后,在文本框中输入abc,则窗体上输出的内容是 【8】 。答案:aababc
1.在窗体上放置一个计时器和一个标签,计时器名称为Timer1,标签名称为Label1。下列程序的功能是:
(1)在窗体加载事件中设置计时器每秒钟能够触发5次Timer事件;
(2)每触发一次Timer事件能够将标签上的字号加大2,当字号超过当前窗体的宽度时,将字号恢复为8。
程序中有一处错误,请更正。说明错误时可以使用每条语句前的编号。 ..(1) Private Sub Form_Load() (2) = 5 答案:200 (3) = True (4) End Sub (5) Private Sub Timer1_Timer() (6) = + 2 (7) If > Then (8) = 8 (9) End If (10) End Sub
2.下列程序的功能是计算1+3+5+…+99的和s。程序中有一处错误。请更正。说明错误时..可以使用每条语句前的编号。 (1) (2) (3) (4) (5) (6) (7)
s = 0 k = 1
Do While k <= 99
k = k + 2 答案:将(4)、(5)调换顺序 s = s + k Loop Print s
1.在窗体上放置一个列表框,名称为List1;放置一
个文本框,名称为Text1;放置一个命令按钮,名称为Command1,Caption属性值为“统计3的倍数”。如右图所示。
下列程序的功能是:
(1) 在窗体的Load事件中,产生10个20~30
(含20和30)之间的随机整数,并作为列表项逐个添加到列表框List1中。
(2) 单击命令按钮Command1时,能够统计列表框中是3的倍数的列表项的个数,并
将统计结果显示在文本框Text1中。 请填空完善程序。
Private Sub Form_ Load( )
Dim x As Integere
Randomize
For k = 1 To 10 答案:Int(Rnd * 11 + 20) 或 Rnd*10+20 x = 【1】 '产生一个[20,30]之间的随机整数 【2】 '将x作为列表项添加到List1中 Next k 答案: x 或 str(x) End Sub
Private Sub Command1_Click()
Dim n As Integer ' n:存放是3的倍数的列表项的个数 For k = 【3】 答案:0 To – 1 或 0 To 9 If Val(k)) 【4】 = 0 Then 答案: Mod 3 n = n + 1 End If Next k = n End Sub
2.下列程序的功能是用近似公式 e11111 求自然对数的底 e 的值,1!2!3!n!直到最后一项小于10-4时停止计算。请填空完善程序。 Private Sub Form_Click()
Dim e As Single, n As Integer, p As Single 'e: 累加和 p: 参加求和的当前项 e = 1: n = 1: p = 1
Do While 【5】 答案:p >= 1e-4 e = e + p
n = n + 1
p = 【6】 答案:p / n Loop
Print \"e的近似值=\"; e End Sub
3.在下图所示的窗体上放置的主要控件及其主要的属性设置如下:
控件类型 控件名称 标签 Label1 属性 属性值 Caption 示例文字 命令按钮 Command1 Caption 设置 Option1 单选按钮 Option2 Caption 隶书
下列程序的功能是单击命令按钮后,根据单选按钮的选中状态,将标签中的“示例文字”设置为相应的字体。请填空完善程序。 Private Sub Command1_Click()
Dim fn As String ' fn:存放选中的字体 If 【7】 Then 答案: = True fn = \"宋体\" Else
fn = \"隶书\" End If
【8】 = fn 答案:
Caption 宋体 End Sub
4.下列程序中用户自定义函数ave的功能是求一维数组中所有元素的平均值,并返回。
单击窗体时,能够输入数组a的10个元素,并调用函数ave,求数组a中所有元素的平均值,并显示输出。
请填空完善程序。 Option Base 1
Private Sub Form_Click() Dim a(10) As Single For i = 1 To 10
a(i) = Val(InputBox(\"输入一个数值\")) Next i
Print \"平均值=\"; 【9】 '调用函数ave 答案:ave(a) End Sub
Public Function ave(b() As Single) As Single Dim s As Single Dim n As Integer n = UBound(b) For k = 1 To n s = s + b(k) Next k
【10】 答案:ave = s / n End Function
《VB期末范围题总汇》
1. 求随机10个整数的最大值、最小值、平均值以及和;
Dim a(1 To 10)
Private Sub Command1_Click() Randomize
\"产生的随机数为:\" For i = 1 To 10
a(i) = Int(Rnd * 99 + 1) a(i); Next i
End Sub
Private Sub Command2_Click() Dim max, min, ave max = a(1) min = a(1) ave = * a(1) For i = 2 To 10
If a(i) > max Then max = a(i)
If a(i) < min Then min = a(i) ave = ave + * a(i) Next i
\"最大数为:\"; max \"最小数为:\"; min \"平均数为:\"; ave
End Sub
2.求水仙花数
Private Sub Form_Click()
Dim a, b, c As Integer 'a(个)b(十)c(百) For a = 0 To 9 For b = 0 To 9 For c = 1 To 9
If a ^ 3 + b ^ 3 + c ^ 3 = a + 10 * b + 100 * c Then MsgBox 100 * c + 10 * b + a End If Next c Next b Next a End Sub
3.百元买百鸡问题; Option Explicit
Const a = 5, b = 3, c = 1
Private Sub Form_Activate()
Dim i As Integer, j As Integer, k As Integer, n As Integer For i = 1 To 100 For j = 1 To 100 For k = 1 To 100
If i * a + j * b + k * c = 100 Then n = n + 1
\" 公鸡:\" & i & \" 母鸡:\" & j & \" 小鸡:\" & k End If
Next: Next: Next
MsgBox \"共有组合:\" & n End Sub
求1000以内的所有完数 一个按钮里调用的过程
Private Sub Command1_Click() OutputWanNumber 1000 End Sub
4.'求完数的过程
Private Sub Form_Click() Dim i, j As Integer For i = 4 To 100 temp = 1
For j = 2 To i / 2 If i Mod j = 0 Then temp = temp + j End If Next j
If temp = i Then Print i End If Next i End Sub
5.求各位数字之和 input a:'输入任意数 do
b=a mod 10:'取a的末位数 sum=sum+b:'求和 a=a \\ 10:'去掉末位数 loop until a=0
print \"sum=\";sum:'输出 end
(dim n as string input n
for i = 1 to len(n)
sum=sum+val(mid(n,i,1)) next i
print sum) 6.求最小公倍数
Private Sub Form_Load() = True
Dim n1%, m1%, m%, n%, r% n1 = InputBox(\"输入n1\") m1 = InputBox(\"输入m1\")
If m1 > n1 Then '为了求最小公倍数,增加m,n变量 m = m1: n = n1 Else
m = n1: n = m1 End If Do
r = m Mod n
If r = 0 Then Exit Do m = n
n = r Loop
Print n1; \的最大公约数为\"; n Print \"最小公倍数=\End Sub
7.求逆序数(感觉题目类型太多)
8. 级数有限项求和问题(题目类型太多)
9. 求质因子问题
Private Sub Command1_Click() Dim N As Integer, I As Integer
N = Val(InputBox(\"请输入2的整数:\")) I = 2 Do
If N Mod I = 0 Then Print I; N = N \\ I Else I = I 1 End If
Loop While N 1 End Sub
10. 字符统计 Option Base1 Option Explicit
Private Sub Command1_Click()
Dim i as integer,A(26) as integer,n as integer Dim S as string*1,Strl as string Strl=Text1 n=Len(Strl) For i=1 To n S=Mid(Strl,i,1)
If UCase(S)>=”A” And UCase(S)<=”Z” Then A(Asc(UCase(S))-64)+1 End If Next i
For i=1 To 26
Chr(64+i) & “:” & A(i) Netx i End Sub
Private Sub Command_Click() End End Sub
第二大题
1. 判定素数过程
Function isprime(Num As Long) As Boolean If Num < 2 Then isprime = False: Exit Function
Dim i As Long
For i = 2 To Sqr(Num) If (Num Mod i) = 0 Then isprime = False Exit Function End If Next i
isprime = True End Function
Private Sub Command1_Click() Dim i As Long
For i = 1 To 1000 If isprime(i) Then Print i End If Next i
End Sub
2.求最大公约数过程;
Function Max公约数(A As Long, B As Long) '求出两个数的最大公约数 Dim X As Long, Y As Long, K As Long X = IIf(A >= B, A, B) 'x存入最大值 Y = IIf(A <= B, A, B) 'y 存入最小值 Do '辗转相除法
K = X Mod Y: If K = 0 Then Exit Do X = Y: Y = K Loop
Max公约数 = Y End Function
3.冒泡排序过程
Private Sub Command1_Click() Dim a(9) As Integer Dim i As Integer
For i = 0 To 9
a(i) = InputBox(\"输入整数\")
Next Sort a
For i = 0 To 9 Print a(i) Next End Sub
Private Sub Sort(ByRef a() As Integer) Dim i As Integer Dim j As Integer Dim t As Integer
For i = LBound(a) + 1 To UBound(a) For j = UBound(a) To i Step -1 If a(j - 1) > a(j) Then t = a(j - 1) a(j - 1) = a(j) a(j) = t End If Next Next End Sub
4顺序查找过程
Private Sub Command1_Click() Dim i, j, t, a(1 To 10) Randomize Print \"原数组:\" For i = 1 To 10
a(i) = Int(Rnd * 10)
Print \"a(\" & i & \") =\" & a(i) & Space(2), If i Mod 2 = 0 Then Print End If Next i Print
For i = 1 To 9
For j = i + 1 To 10 If a(j) < a(i) Then t = a(i) End If Next j Next i End Sub
《VB期末范围题总汇》
1. 求随机10个整数的最大值、最小值、平均值以及和;
Dim a(1 To 10)
Private Sub Command1_Click() Randomize
\"产生的随机数为:\" For i = 1 To 10
a(i) = Int(Rnd * 99 + 1) a(i); Next i
End Sub
Private Sub Command2_Click() Dim max, min, ave max = a(1) min = a(1) ave = * a(1) For i = 2 To 10
If a(i) > max Then max = a(i) If a(i) < min Then min = a(i) ave = ave + * a(i) Next i
\"最大数为:\"; max \"最小数为:\"; min \"平均数为:\"; ave
End Sub
2.求水仙花数
Private Sub Form_Click()
Dim a, b, c As Integer 'a(个)b(十)c(百) For a = 0 To 9 For b = 0 To 9 For c = 1 To 9
If a ^ 3 + b ^ 3 + c ^ 3 = a + 10 * b + 100 * c Then MsgBox 100 * c + 10 * b + a End If Next c Next b Next a End Sub
3.百元买百鸡问题; Option Explicit
Const a = 5, b = 3, c = 1
Private Sub Form_Activate()
Dim i As Integer, j As Integer, k As Integer, n As Integer For i = 1 To 100 For j = 1 To 100 For k = 1 To 100
If i * a + j * b + k * c = 100 Then n = n + 1
\" 公鸡:\" & i & \" 母鸡:\" & j & \" 小鸡:\" & k End If
Next: Next: Next
MsgBox \"共有组合:\" & n End Sub
求1000以内的所有完数 一个按钮里调用的过程
Private Sub Command1_Click() OutputWanNumber 1000 End Sub
4.'求完数的过程
Private Sub Form_Click() Dim i, j As Integer For i = 4 To 100 temp = 1
For j = 2 To i / 2 If i Mod j = 0 Then temp = temp + j End If Next j
If temp = i Then Print i End If Next i End Sub
5.求各位数字之和 input a:'输入任意数 do
b=a mod 10:'取a的末位数 sum=sum+b:'求和 a=a \\ 10:'去掉末位数 loop until a=0
print \"sum=\";sum:'输出 end
(dim n as string input n
for i = 1 to len(n)
sum=sum+val(mid(n,i,1)) next i
print sum) 6.求最小公倍数
Private Sub Form_Load() = True
Dim n1%, m1%, m%, n%, r% n1 = InputBox(\"输入n1\") m1 = InputBox(\"输入m1\")
If m1 > n1 Then '为了求最小公倍数,增加m,n变量 m = m1: n = n1 Else
m = n1: n = m1 End If Do
r = m Mod n
If r = 0 Then Exit Do m = n n = r Loop
Print n1; \的最大公约数为\"; n Print \"最小公倍数=\End Sub
7.求逆序数(感觉题目类型太多)
8. 级数有限项求和问题(题目类型太多)
9. 求质因子问题
Private Sub Command1_Click() Dim N As Integer, I As Integer
N = Val(InputBox(\"请输入2的整数:\")) I = 2 Do
If N Mod I = 0 Then Print I; N = N \\ I Else I = I 1 End If
Loop While N 1 End Sub
10. 字符统计 Option Base1
Option Explicit
Private Sub Command1_Click()
Dim i as integer,A(26) as integer,n as integer Dim S as string*1,Strl as string Strl=Text1 n=Len(Strl) For i=1 To n S=Mid(Strl,i,1)
If UCase(S)>=”A” And UCase(S)<=”Z” Then A(Asc(UCase(S))-64)+1 End If Next i
For i=1 To 26
Chr(64+i) & “:” & A(i) Netx i End Sub
Private Sub Command_Click() End End Sub 第二大题
1. 判定素数过程
Function isprime(Num As Long) As Boolean If Num < 2 Then isprime = False: Exit Function
Dim i As Long
For i = 2 To Sqr(Num) If (Num Mod i) = 0 Then isprime = False Exit Function End If Next i
isprime = True End Function
Private Sub Command1_Click() Dim i As Long
For i = 1 To 1000 If isprime(i) Then Print i End If Next i
End Sub
2.求最大公约数过程;
Function Max公约数(A As Long, B As Long) '求出两个数的最大公约数 Dim X As Long, Y As Long, K As Long X = IIf(A >= B, A, B) 'x存入最大值 Y = IIf(A <= B, A, B) 'y 存入最小值 Do '辗转相除法
K = X Mod Y: If K = 0 Then Exit Do X = Y: Y = K Loop
Max公约数 = Y End Function
3.冒泡排序过程
Private Sub Command1_Click() Dim a(9) As Integer Dim i As Integer
For i = 0 To 9
a(i) = InputBox(\"输入整数\") Next Sort a
For i = 0 To 9 Print a(i) Next End Sub
Private Sub Sort(ByRef a() As Integer) Dim i As Integer Dim j As Integer Dim t As Integer
For i = LBound(a) + 1 To UBound(a) For j = UBound(a) To i Step -1 If a(j - 1) > a(j) Then t = a(j - 1) a(j - 1) = a(j) a(j) = t End If Next Next End Sub
4顺序查找过程
Private Sub Command1_Click() Dim i, j, t, a(1 To 10) Randomize
Print \"原数组:\" For i = 1 To 10 a(i) = Rnd * 10
Print \"a(\" & i & \") =\" & a(i) & Space(2), If i Mod 2 = 0 Then Print Next i Print
For i = 1 To 9 For j = i + 1 To 10 If a(j) < a(i) Then t = a(i) a(i
《VB期末范围题总汇》
1. 求随机10个整数的最大值、最小值、平均值以及和;
Dim a(1 To 10)
Private Sub Command1_Click() Randomize
\"产生的随机数为:\" For i = 1 To 10
a(i) = Int(Rnd * 99 + 1) a(i); Next i
End Sub
Private Sub Command2_Click() Dim max, min, ave max = a(1) min = a(1) ave = * a(1) For i = 2 To 10
If a(i) > max Then max = a(i) If a(i) < min Then min = a(i) ave = ave + * a(i) Next i
\"最大数为:\"; max \"最小数为:\"; min \"平均数为:\"; ave
End Sub
2.求水仙花数
Private Sub Form_Click()
Dim a, b, c As Integer 'a(个)b(十)c(百) For a = 0 To 9
For b = 0 To 9 For c = 1 To 9
If a ^ 3 + b ^ 3 + c ^ 3 = a + 10 * b + 100 * c Then MsgBox 100 * c + 10 * b + a End If Next c Next b Next a End Sub
3.百元买百鸡问题; Option Explicit
Const a = 5, b = 3, c = 1
Private Sub Form_Activate()
Dim i As Integer, j As Integer, k As Integer, n As Integer For i = 1 To 100 For j = 1 To 100 For k = 1 To 100
If i * a + j * b + k * c = 100 Then n = n + 1
\" 公鸡:\" & i & \" 母鸡:\" & j & \" 小鸡:\" & k End If
Next: Next: Next
MsgBox \"共有组合:\" & n End Sub
求1000以内的所有完数 一个按钮里调用的过程
Private Sub Command1_Click() OutputWanNumber 1000 End Sub
4.'求完数的过程
Private Sub Form_Click() Dim i, j As Integer For i = 4 To 100 temp = 1
For j = 2 To i / 2 If i Mod j = 0 Then temp = temp + j End If Next j
If temp = i Then Print i End If Next i End Sub
5.求各位数字之和 input a:'输入任意数 do
b=a mod 10:'取a的末位数 sum=sum+b:'求和 a=a \\ 10:'去掉末位数 loop until a=0
print \"sum=\";sum:'输出 end
(dim n as string input n
for i = 1 to len(n)
sum=sum+val(mid(n,i,1)) next i
print sum) 6.求最小公倍数
Private Sub Form_Load() = True
Dim n1%, m1%, m%, n%, r% n1 = InputBox(\"输入n1\") m1 = InputBox(\"输入m1\")
If m1 > n1 Then '为了求最小公倍数,增加m,n变量 m = m1: n = n1 Else
m = n1: n = m1 End If Do
r = m Mod n
If r = 0 Then Exit Do m = n n = r Loop
Print n1; \的最大公约数为\"; n Print \"最小公倍数=\End Sub
7.求逆序数(感觉题目类型太多)
8. 级数有限项求和问题(题目类型太多)
9. 求质因子问题
Private Sub Command1_Click() Dim N As Integer, I As Integer
N = Val(InputBox(\"请输入2的整数:\"))
I = 2 Do
If N Mod I = 0 Then Print I; N = N \\ I Else I = I 1 End If
Loop While N 1 End Sub
10. 字符统计 Option Base1 Option Explicit
Private Sub Command1_Click()
Dim i as integer,A(26) as integer,n as integer Dim S as string*1,Strl as string Strl=Text1 n=Len(Strl) For i=1 To n S=Mid(Strl,i,1)
If UCase(S)>=”A” And UCase(S)<=”Z” Then A(Asc(UCase(S))-64)+1 End If Next i
For i=1 To 26
Chr(64+i) & “:” & A(i) Netx i End Sub
Private Sub Command_Click() End End Sub 第二大题
1. 判定素数过程
Function isprime(Num As Long) As Boolean If Num < 2 Then isprime = False: Exit Function
Dim i As Long
For i = 2 To Sqr(Num) If (Num Mod i) = 0 Then isprime = False Exit Function End If Next i
isprime = True
End Function
Private Sub Command1_Click() Dim i As Long
For i = 1 To 1000 If isprime(i) Then Print i End If Next i
End Sub
2.求最大公约数过程;
Function Max公约数(A As Long, B As Long) '求出两个数的最大公约数 Dim X As Long, Y As Long, K As Long X = IIf(A >= B, A, B) 'x存入最大值 Y = IIf(A <= B, A, B) 'y 存入最小值 Do '辗转相除法
K = X Mod Y: If K = 0 Then Exit Do X = Y: Y = K Loop
Max公约数 = Y End Function
3.冒泡排序过程
Private Sub Command1_Click() Dim a(9) As Integer Dim i As Integer
For i = 0 To 9
a(i) = InputBox(\"输入整数\") Next Sort a
For i = 0 To 9 Print a(i) Next End Sub
Private Sub Sort(ByRef a() As Integer) Dim i As Integer Dim j As Integer Dim t As Integer
For i = LBound(a) + 1 To UBound(a) For j = UBound(a) To i Step -1 If a(j - 1) > a(j) Then
t = a(j - 1) a(j - 1) = a(j) a(j) = t End If Next Next End Sub
4顺序查找过程
Private Sub Command1_Click() Dim i, j, t, a(1 To 10) Randomize Print \"原数组:\" For i = 1 To 10 a(i) = Rnd * 10
Print \"a(\" & i & \") =\" & a(i) & Space(2), If i Mod 2 = 0 Then Print Next i Print
For i = 1 To 9 For j = i + 1 To 10 If a(j) < a(i) Then t = a(i) a(i
《VB期末范围题总汇》
1. 求随机10个整数的最大值、最小值、平均值以及和;
Dim a(1 To 10)
Private Sub Command1_Click() Randomize
\"产生的随机数为:\" For i = 1 To 10
a(i) = Int(Rnd * 99 + 1) a(i); Next i
End Sub
Private Sub Command2_Click() Dim max, min, ave max = a(1) min = a(1) ave = * a(1) For i = 2 To 10
If a(i) > max Then max = a(i)
If a(i) < min Then min = a(i) ave = ave + * a(i) Next i
\"最大数为:\"; max \"最小数为:\"; min \"平均数为:\"; ave
End Sub
2.求水仙花数
Private Sub Form_Click()
Dim a, b, c As Integer 'a(个)b(十)c(百) For a = 0 To 9 For b = 0 To 9 For c = 1 To 9
If a ^ 3 + b ^ 3 + c ^ 3 = a + 10 * b + 100 * c Then MsgBox 100 * c + 10 * b + a End If Next c Next b Next a End Sub
3.百元买百鸡问题; Option Explicit
Const a = 5, b = 3, c = 1
Private Sub Form_Activate()
Dim i As Integer, j As Integer, k As Integer, n As Integer For i = 1 To 100 For j = 1 To 100 For k = 1 To 100
If i * a + j * b + k * c = 100 Then n = n + 1
\" 公鸡:\" & i & \" 母鸡:\" & j & \" 小鸡:\" & k End If
Next: Next: Next
MsgBox \"共有组合:\" & n End Sub
求1000以内的所有完数 一个按钮里调用的过程
Private Sub Command1_Click() OutputWanNumber 1000 End Sub
4.'求完数的过程
Private Sub Form_Click() Dim i, j As Integer For i = 4 To 100 temp = 1
For j = 2 To i / 2 If i Mod j = 0 Then temp = temp + j End If Next j
If temp = i Then Print i End If Next i End Sub
5.求各位数字之和 input a:'输入任意数 do
b=a mod 10:'取a的末位数 sum=sum+b:'求和 a=a \\ 10:'去掉末位数 loop until a=0
print \"sum=\";sum:'输出 end
(dim n as string input n
for i = 1 to len(n)
sum=sum+val(mid(n,i,1)) next i
print sum) 6.求最小公倍数
Private Sub Form_Load() = True
Dim n1%, m1%, m%, n%, r% n1 = InputBox(\"输入n1\") m1 = InputBox(\"输入m1\")
If m1 > n1 Then '为了求最小公倍数,增加m,n变量 m = m1: n = n1 Else
m = n1: n = m1 End If Do
r = m Mod n
If r = 0 Then Exit Do m = n
n = r Loop
Print n1; \的最大公约数为\"; n Print \"最小公倍数=\End Sub
7.求逆序数(感觉题目类型太多)
8. 级数有限项求和问题(题目类型太多)
9. 求质因子问题
Private Sub Command1_Click() Dim N As Integer, I As Integer
N = Val(InputBox(\"请输入2的整数:\")) I = 2 Do
If N Mod I = 0 Then Print I; N = N \\ I Else I = I 1 End If
Loop While N 1 End Sub
10. 字符统计 Option Base1 Option Explicit
Private Sub Command1_Click()
Dim i as integer,A(26) as integer,n as integer Dim S as string*1,Strl as string Strl=Text1 n=Len(Strl) For i=1 To n S=Mid(Strl,i,1)
If UCase(S)>=”A” And UCase(S)<=”Z” Then A(Asc(UCase(S))-64)+1 End If Next i
For i=1 To 26
Chr(64+i) & “:” & A(i) Netx i End Sub
Private Sub Command_Click() End End Sub
第二大题
1. 判定素数过程
Function isprime(Num As Long) As Boolean If Num < 2 Then isprime = False: Exit Function
Dim i As Long
For i = 2 To Sqr(Num) If (Num Mod i) = 0 Then isprime = False Exit Function End If Next i
isprime = True End Function
Private Sub Command1_Click() Dim i As Long
For i = 1 To 1000 If isprime(i) Then Print i End If Next i
End Sub
2.求最大公约数过程;
Function Max公约数(A As Long, B As Long) '求出两个数的最大公约数 Dim X As Long, Y As Long, K As Long X = IIf(A >= B, A, B) 'x存入最大值 Y = IIf(A <= B, A, B) 'y 存入最小值 Do '辗转相除法
K = X Mod Y: If K = 0 Then Exit Do X = Y: Y = K Loop
Max公约数 = Y End Function
3.冒泡排序过程
Private Sub Command1_Click() Dim a(9) As Integer Dim i As Integer
For i = 0 To 9
a(i) = InputBox(\"输入整数\")
Next Sort a
For i = 0 To 9 Print a(i) Next End Sub
Private Sub Sort(ByRef a() As Integer) Dim i As Integer Dim j As Integer Dim t As Integer
For i = LBound(a) + 1 To UBound(a) For j = UBound(a) To i Step -1 If a(j - 1) > a(j) Then t = a(j - 1) a(j - 1) = a(j) a(j) = t End If Next Next End Sub
4顺序查找过程
Private Sub Command1_Click() Dim i, j, t, a(1 To 10) Randomize Print \"原数组:\" For i = 1 To 10 a(i) = Rnd * 10
Print \"a(\" & i & \") =\" & a(i) & Space(2), If i Mod 2 = 0 Then Print Next i Print
For i = 1 To 9 For j = i + 1 To 10 If a(j) < a(i) Then t = a(i) a(i