求几个VB编程解答
发布网友
发布时间:2024-09-27 13:24
我来回答
共1个回答
热心网友
时间:2024-10-25 12:20
第二题:思路:
1.输入一个正整数n
2.如果n为奇数,I = n+1,否则I = n+2
用i为初值开始循环,每次循环i递增2,这样保证I就是大于n的偶数。
设置变量c = 0,作为计数器,每找到一个满足要求(I mod 3 = 0)的数就计数器加1,
当c = 10循环结束。
代码如下:
Dim n As Integer
Dim i As Integer
Dim c As Integer
Me.Cls
n = InputBox("请输入一个正整数")
If n Mod 2 = 0 Then
i = n + 2
Else
i = n + 1
End If
c = 0
Do While c < 10
If i Mod 3 = 0 Then
c = c + 1
Print i
End If
i = i + 2
Loop
'====================================================
第3题:代码:
Dim S As Integer
Dim x As Integer
Dim i As Integer
Dim Max As Integer
Dim Min As Integer
Dim Ave As Single
Max = -1
Min = 100
S = 0
Randomize
For i = 1 To 10
x = Int((90 * Rnd) + 10)
Print x
S = S + x
If x > Max Then Max = x
If x < Min Then Min = x
Next i
Ave = S / 10
Print Max, Min, Ave
'====================================================
第4题:代码:
Dim d(1 To 100) As Integer
Dim x As Integer
Dim n As Integer
Dim YesNo As Boolean
Dim i As Integer
'产生100个互不相等的三位正整数
Randomize
n = 0
Do While n < 100
x = Int((900 * Rnd) + 1) + 99
YesNo = False
For i = 1 To n
If d(i) = x Then
YesNo = True
Exit For
End If
Next i
If Not YesNo Then
n = n + 1
d(n) = x
End If
Loop
x = InputBox("请输入一个三位正整数")
'开始寻找
n = 0
For i = 1 To 100
If x = d(i) Then
n = i
Exit For
End If
Next i
If n = 0 Then
Print "要寻找的数:" & x & "不存在!"
Else
Print "要寻找的数:" & x & "在第" & n & "个元素中。"
End If
'====================================================
第5题:代码:
添加1个文本框和1个按钮:
Private Sub Command1_Click()
If Text1.Text = "ABCD" Then
MsgBox "口令正确!"
Else
MsgBox "口令错误!"
End If
End Sub