文章目录
目录
系列文章目录
前言
题目
一、输出以下图案。
四、单击窗体,生成0~10之间的随机整数矩阵,分别放在两个图画框内,求两个矩阵之和放入第三个图画框内。
五、实现点餐功能,界面如图 2-1 所示。程序运行后,单击“点餐总计”按钮,实现将选餐结果显示在文本框中。
六、.在文本框输入大于10的偶数,找出最接近这个数的素数,输出在窗体上
七、下面程序的功能是计算,若通项分母的值>=200,停止计算(正确答案是S=1.409524)
S=1+1/1*3 + 1/1*3*5 +1/1*3*5*7…..
八、点击窗体,用inputbox输出9个整数,放入数组a中并输出在窗体上,本程序按序号依次将(a1,a2,a3),(a2,a3,a4),…..(a9,a1,a2),九组元素分别相加(每组3个元素),生产新数组b并输出在窗体上,然后找出b数组中的最大元素并输出在窗体上。
九、.随机生成9个数(范围为1~99)的数列,输出在窗体上,新数列的规则是:序列左边是奇数,序列右是偶数,奇、偶数分别从序列的两端开始依次向序列中间排放。
十、.在窗体上输出二维数i*j的字符数组,并求出将此数组顺时针旋转90°后的新数组。
总结
前言
上大学了,学业繁忙,偶尔发一下题。谢谢支持。
题目
一、输出以下图案。
答案:
Private Sub Form_Click()
s = 0
For i = 1 To 3
Print Space(9 – 3 * i);
For j = 1 To 2 * i – 1
s = s + 1 就等于1~9
Print s;
Next
Next
End Sub
二、该题是求丢番年龄问题,丢番生命的1/6是童年,又过了1/12长胡子,再过了的1/7结婚,婚后5年生儿子,儿子活了父亲年龄的一半死亡,之后丢番图又过了4年死亡,求丢番图的年龄
答案:
Private Sub Command1_Click()
n = 0 ‘先从0岁开始
Do While n < n / 6 + n / 12 + n / 7 + n / 2 + 4 ,直到不满足条件停止循环
n = n + 1 一直加1
Loop
Text1.Text = n
End Sub
三、
Private Sub Command1_Click()
Dim a(1 To 4, 1 To 5)
For i = 1 To 4
For j = 1 To 5
a(i, j) = Int(Rnd * (99 – 51 + 1) + 51)
Print a(i, j);
If a(i, j) > Max Then
Max = a(i, j)
n = i
m = j
End If
Next
Next
Print "最大值的所在的行列号为" & "第" & n & "行" & " " & "第" & m & "列"
End Sub
四、单击窗体,生成0~10之间的随机整数矩阵,分别放在两个图画框内,求两个矩阵之和放入第三个图画框内。
答案:
Dim a(1 To 5, 1 To 4)
Dim b(1 To 5, 1 To 4)
Dim c(1 To 5, 1 To 4)
Private Sub Command1_Click()
For i = 1 To 5
For j = 1 To 4
c(i, j) = a(i, j) + b(i, j)
P3.Print c(i, j);
Next
P3.Print
Next
End Sub
Private Sub Form_Click()
Dim i, j As Integer
Randomize
For i = 1 To 5
For j = 1 To 4
a(i, j) = Int(Rnd * (10 – 0 + 1) + 0)
P1.Print a(i, j);
Next
P1.Print
Next
For n = 1 To 5
For m = 1 To 4
b(n, m) = Int(Rnd * (10 – 0 + 1) + 0)
P2.Print b(n, m);
Next
P2.Print
Next
End Sub
五、实现点餐功能,界面如图 2-1 所示。程序运行后,单击“点餐总计”按钮,实现将选餐结果显示在文本框中。
答案:
Private Sub Command1_Click()
Dim s As String
If Option1.Value = True Then
s = "米饭"
End If
If Option2.Value = True Then s = "炒面"
If Check1.Value = 1 Then s = s & Check1.Caption
If Check2.Value = 1 Then s = s & Check2.Caption
Text1.Text = "您点的食物是:" & s
End Sub
六、.在文本框输入大于10的偶数,找出最接近这个数的素数,输出在窗体上
答案:
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
min = 10
b = 0
a = Val(Text1.Text)
If a > 10 And a Mod 2 = 0 Then
For i = 2 To Val(a + 10)
f = 0
For j = 2 To i – 1
If i Mod j = 0 Then
f = 1
Exit For
Else
f = 0
End If
Next
If f = 0 Then
If Abs(a – i) < min Then
min = Abs(a – i)
b = i
End I
End If
Next
Print b
Else
MsgBox "请输入大于10的偶数"
End If
End Sub
七、下面程序的功能是计算,若通项分母的值>=200,停止计算(正确答案是S=1.409524)
S=1+1/1*3 + 1/1*3*5 +1/1*3*5*7…..
答案:
Private Sub Form_Click()
Dim i As Integer
Dim n As Integer
i = 1
n = 1
Do
If n > 200 Then
Exit Do
Else
Print i
Sum = Sum + (1 / n)
End If
i = i + 2
n = n * i
Loop
Print Sum
End Sub
第二种:
Private Sub Form_Click()
Dim i As Integer
Dim n As Integer
i = 1
n = 1
Do While n <= 200
Sum = Sum + (1 / n)
i = i + 2
n = n * i
Loop
Print Sum
End Sub
八、点击窗体,用inputbox输出9个整数,放入数组a中并输出在窗体上,本程序按序号依次将(a1,a2,a3),(a2,a3,a4),…..(a9,a1,a2),九组元素分别相加(每组3个元素),生产新数组b并输出在窗体上,然后找出b数组中的最大元素并输出在窗体上。
答案:
Dim a(1 To 9) As Integer
Dim b(1 To 9) As Integer
Private Sub Command1_Click()
Dim c1, c2, c3 As Integer
Print "数组b的数有:";
For i = 1 To 9
c1 = i
c2 = i + 1
c3 = i + 2
If c2 > 9 Then
c2 = c2 – 9
End If
If c3 > 9 Then
c3 = c3 – 9
End If
b(i) = a(c1) + a(c2) + a(c3)
Print b(i);
Next
For i = 1 To 9
If b(i) > Max Then
Max = b(i)
End If
Next
Print "数组b中最大数是" & Max
End Sub
Private Sub Form_Click()
Print "数组a的数有:";
For i = 1 To 9
a(i) = Val(InputBox("请输入第" & i & "个数"))
Print a(i);
Next
End Sub
九、.随机生成9个数(范围为1~99)的数列,输出在窗体上,新数列的规则是:序列左边是奇数,序列右是偶数,奇、偶数分别从序列的两端开始依次向序列中间排放。
答案:
Private Sub Form_Click()
Dim a(1 To 9)
Dim b(1 To 9)
Randomize
Print "原序列是:";
For i = 1 To 9
a(i) = Int(Rnd * (100 – 1 + 1) + 1)
Print a(i);
Next
Print "新序列为:";
For i = 1 To 9
For j = 9 To i + 1 Step -1
If a(i) Mod 2 = 0 And a(j) Mod 2 <> 0 Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Print a(i);
Next
End Sub
十、.在窗体上输出二维数i*j的字符数组,并求出将此数组顺时针旋转90°后的新数组。
答案:
Dim a(1 To 4, 1 To 3)
Private Sub Form_Click()
For i = 1 To 3
For j = 4 To 1 Step -1
Print a(j, i); Space(1);
Next
Next
End Sub
Private Sub Form_Load()
Dim s As Integer
For i = 1 To 4
For j = 1 To 3
s = s + 1
a(i, j) = Chr(96 + s)
Print a(i, j); Space(1);
Next
Next
End Sub
总结
多思考多练习多总结。