vb 随机产生20个三位正整数存入一维数组A中,找出其中升序数,回文数定义两个function过程,来判断一个数是否为回文数、升序数.
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/20 00:26:58
vb 随机产生20个三位正整数存入一维数组A中,找出其中升序数,回文数定义两个function过程,来判断一个数是否为回文数、升序数.
vb 随机产生20个三位正整数存入一维数组A中,找出其中升序数,回文数
定义两个function过程,来判断一个数是否为回文数、升序数.
vb 随机产生20个三位正整数存入一维数组A中,找出其中升序数,回文数定义两个function过程,来判断一个数是否为回文数、升序数.
Private Sub Command1_Click()
Dim a%(0 To 19), b%(0 To 19), hwsN%, sxsN%
Dim sxsbz As Boolean, hwsbz As Boolean
Print "随机产生20个三位正整数如下:";
For i = 0 To 19
Randomize
a(i) = Int(Rnd * 900 + 100)
If i Mod 5 = 0 Then Print
Print a(i);
Next i
Print
Print "其中有升序数:";
For i = 0 To 19
Call sxs(a(i), sxsbz)
If sxsbz Then
Print a(i);
sxsN = sxsN + 1
End If
Next i
Print sxsN & "个.";
Print
Print "其中有回文数:";
For i = 0 To 19
Call hws(a(i), hwsbz)
If hwsbz Then
Print a(i);
hwsN = hwsN + 1
End If
Next i
Print hwsN & "个."
End Sub
Private Function sxs(n As Integer, bz As Boolean) '判断所给n是不是升序数,是的话,bz返回true,否返回false
Dim a%, b%, c%, tmp%
tmp = Trim(Str(n))
a = Mid(tmp, 1, 1)
b = Mid(tmp, 2, 1)
c = Mid(tmp, 3, 1)
If (a < b) And (b < c) Then bz = True Else bz = False
End Function
Private Function hws(n As Integer, bz As Boolean) '判断所给n是不是回文数,是的话,bz返回true,否返回false
If Trim(Str(n)) = Trim(StrReverse(Str(n))) Then bz = True Else bz = False
End Function