同构数如何用VB编写程序
发布网友
发布时间:2023-04-23 01:33
我来回答
共3个回答
热心网友
时间:2023-10-30 14:20
Private Sub Command1_Click()
Label1.Caption = ""
Dim i As Integer
For i = 1 To Val(Text1.Text)
If i = Right(i ^ 2, Len(CStr(i))) Then
Label1.Caption = Label1.Caption & Str(i)
End If
Next
End Sub
热心网友
时间:2023-10-30 14:20
Private Sub Command1_Click()
Dim n As Long, i As Long, j As Long
n = Int(Val(Trim(InputBox("请输入一个整数:", "提示信息"))))
For i = 1 To n
j = i ^ 2
If CStr(i) = Right(CStr(j), Len(CStr(i))) Then Print i
Next i
End Sub
热心网友
时间:2023-10-30 14:22
同构数就是某个数的平方以该数结尾,例如 5² = 25,25² = 625,都是。所以你用字符串的 EndWith 方法就行了:
dim zhs原数 as integer
dim zhs平方数 as integer
dim zhs个数 as integer
for zhs as integer = 1 to 100
zhs原数 = zhs
zhs平方数 = zhs原数 ^ 2
dim zfc平方字符串 as string = zhs平方数.ToString
dim zfc原数字符串 as string = zhs原数.ToString
if zhc平方字符串.EndWith(zfc原数字符串) then
zhs个数 += 1
end if
msgbox(zhs个数)