程序填空
1.马克思曾经做过这样一道趣味数学题:有30个人在一家小饭店里用餐,其中有男人、女人和小孩,每个男人花了3先令,每个女人花了2先令,每个小孩花了1先令,共花去34先令。求小孩的人数。
Private Sub Command1_Click()
n = 0
For m = 1 To 28
For w = 1 To 28
s = m * 3 + w * 2 + c
If s = 34 Then Print c
Next w
Next m
End Sub
2.“水仙花数”是指这样的数,其各位数字的立方和等于该数本身,如: 153=1^3+5^3+3^3。求100至999的范围内所有奇数中的水仙花数之和。
Private Sub Form_Click()
Dim i%, a%, b%, c%, sum%
FontSize = 14: FontBold = True
sum = 0
I = 100
Do
a = I \ 100
b = I \ 10 Mod 10
c = I Mod 10
Then
sum = sum + I
End If
I = I + 1
Loop While I <= 999
Print sum
End Sub
3.编程求1-99的平方和并输出结果。(328350)
Private Sub Form_Click()
Dim i As Integer, s As Single
For i = 1 To 99
Next i
FontSize = 12
FontBold = True
Print s
End Sub
4.编程求1到5000之间的能被5整除的前若干个奇数之和,当和大于500时,终止求和,并输出该和
Private Sub Form_Click()
Dim i As Integer, s As Long
FontSize = 14
FontBold = True
If i Mod 2 <> 0 Then s = s + i
If s > 500 Then Exit For
Next i
Print s
End Sub
5.编程求在四位数的奇数中,所有各位数字之和是25的倍数的数之和。(1298515)
Private Sub Form_Click()
Dim m%, a%, b%, c%, d%, s&
s = 0
FontSize = 14: FontBold = True
Print: Print: Print
For m = 1001 To 9999 Step 2
a = Int(m / 1000)
b = Int((m - 1000 * a) / 100)
c = Int((m - 1000 * a - 100 * b) / 10)
d = m Mod 10
If Then s = s + m
Next m
Print s
End Sub
6.编程求在四位数的偶数中,所有各位数字之积是25的倍数的数之和。(555500)
Private Sub Command1_Click()
sum = 0
For i = 1000 To 9999 Step 2
d1 = i Mod 10
d2 = (i \ 10) Mod 10
d3 = (i \ 100) Mod 10
d4 = i \ 1000
d = d1 * d2 * d3 * d4
If Then sum = sum + i
Next i
Print sum
End Sub
7.编写一个程序,求一个最大的正整数N,使N!<5000。
Private Sub Command1_Click()
Dim n As Integer, f As Long
f = 1
n = 1
While
f = f * n
n = n + 1
Wend
Print n-1
End Sub
8.某人想将手中的一张面值100元的人民币换成5元、1元和0.5元面值的票子50张,且要求每种至少1张。求换法的种数。
Private Sub Form_Click()
Dim i, j, k As Integer, RMBsum As Integer
RMBsum = 0
For i = 1 To 19
For j = 1 To 48
k = 50 - i - j
If Then
RMBsum = RMBsum + 1
Print i; j; k
End If
Next j, i
FontSize = 12: FontBold = True
Print RMBsum
End Sub
9.目前世界上人口为60亿,如果以每年1.4%的速度增长,n(n为正整数)年后世界人口达到80亿,求n。
Private Sub command1_Click()
Dim p As Single
Dim r As Single
Dim n As Integer
FontSize = 14: FontBold = True
p = 60
r = 0.014
n = 0
Do
n = n + 1
Loop Until p >= 80
Print n
End Sub
10.求三位数中,个位数字与十位数字之和除以10所得的余数是百位数字,且百位数字是偶数的数的个数。
Private Sub Form_click()
Dim s As Integer
Dim x As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
s = 0
x = 100
Do While x <= 999
a = Int(x / 100)
b = Int(x / 10) - a * 10
c = x - a * 100 - b * 10
If Then s = s + 1
x = x + 1
Loop
Print s
End Sub
11.求三位数中,个位数字与十位数字之和除以10所得的余数是百位数字,且百位数字是奇数的数的和。
Private Sub Form_click()
Dim s As Integer
Dim x As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
s = 0
x = 100
Do While x <= 999
a = Int(x / 100)
b = Int(x / 10) - a * 10
c = x - a * 100 - b * 10
If Then s = s + x
x = x + 1
Loop
Print s
End Sub
12.求所有水仙花数之和(所谓水仙花数是指一个三位十进制数,该数的各位数字立方之和等于该数本身。例如371是一个水仙花数,因为3^3+7^3+1^3=371)。
Private Sub Command1_Click()
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
n = a * 100 + b * 10 + c
m = a * a * a + b * b * b + c * c * c
If ____________ Then
s = s + n
End If
Next c
Next b
Next a
Print s
End Sub
13.求整数[2335,4321]之间即不能被3整除,又不能被5整除的奇数的个数。(530)
Private Sub Command1_Click()
Dim i As Integer, n As Integer
n = 0
For i = 2335 To 4321 Step 2
If Then
n = n + 1
End If
Next i
Print n
End Sub
14.设某四位数的各位数字的平方和等于100,共有多少个这种四位数?(49)
Private Sub Form_Click()
Dim a, b, c, d, i, count As Integer
count = 0
i = 1111
FontSize = 14: FontBold = True
Print: Print: Print
Do Until i > 9999
a = i \ 1000
b = (i Mod 1000) \ 100
c =
d = i Mod 10
If 100 = a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 Then count = count + 1
i = i + 1
Loop
Print count
End Sub
15.我国古代数学家在《算经》中出了一道题:鸡翁一,值钱五;鸡母一,值钱三;鸡雏三,值钱一。百钱买百鸡,问鸡翁、母、雏各几何?”意为公鸡4吊钱1只,母鸡3吊钱1只,3只小鸡值1吊钱。编程实现用100吊钱买100只鸡,公鸡、母鸡、小鸡每种鸡至少一只,有多少种买法?(2)
Private Sub command1_Click()
Dim a%, b%, c%, s%
FontSize = 14: FontBold = True
Print: Print: Print
s = 0
For a = 1 To 20
For b = 1 To 34
If 4 * a + 3 * b + c / 3 = 100 Then s = s + 1
Next b
Next a
Print s
End Sub
16.要将一张100元的大钞票,换成等值的10元、5元、2元和1元一张的小钞票。要求每次换成50张小钞票,每种至少一张。编程求有多少种换法。(26)
Private Sub Command1_Click()
Dim i, j, k, m As Integer
Dim RMBsum As Integer
FontSize = 14: FontBold = True
For i = 1 To 9
For j = 1 To 17
For k = 1 To 37
m = 50 - i - j - k
If Then RMBsum = RMBsum + 1
Next k, j, i
Print RMBsum
End Sub