輸入一大於1的正整數。平方後取其最小的數字為十位數(若為0則無十位數),最大的為個位數,組成一個2位數,再將此數平方,以上述方式再取得下一個數,直到重複才停止,請列出產生的數列,並標明重複的數。如輸入7則得下列結果:
輸入或產生的新數 平方 最小數 最大數 產生的新數
7 49 4 9 49
49 2401 0 4 4
4 16 1 6 16
16 256 2 6 26
26 676 6 7 67
67 4489 4 9 49
*49
※49重複則停止
輸入說明:大於1之正整數
輸出說明:依規則產生的數列,使用"*"標明重複產生之數字。
輸入範例:7
輸出範例:
7 49
49 2401
4 16
16 256
26 676
67 4489
*49 2401
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As 1
Open App.Path & "\out.txt" For Output As 2
Dim d(100) As Integer
Input #1, x
t = 0
Do
t = t + 1
d(t) = ans
Max = 0
Min = 10
b = x ^ 2
a = Len(b)
For i = 1 To a
c = Val(Mid(b, i, 1))
If c < Min Then Min = c
If c > Max Then Max = c
Next
ans = Val(Min & Max)
Print #2, x, b
x = ans
For i = 1 To t
If d(i) = ans Then
Print #2, "*" & ans,
Print #2, ans ^ 2
Exit Do
End If
Next
Loop
Close
Close
End
End Sub
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As 1
Open App.Path & "\out.txt" For Output As 2
Dim x(100) As Integer
Input #1, n
a = 0
b = 0
c = 0
Do
a = a + 1
x(a) = ans
Max = 0
Min = 10
b = n ^ 2
c = Len(b)
For i = 1 To c
k = Val(Mid(b, i, 1))
If k < Min Then Min = k
If k > Max Then Max = k
Next i
ans = Min & Max
Print #2, n, b
n = ans
For i = 1 To a
If x(i) = ans Then
Print #2, "*" & ans
Exit Do
End If
Next
Loop
Close #2
Close #1
End
End Sub
Private Sub Form_load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, n
Do
Print #2, n;
p = n ^ 2
Print #2, p;
Print #2,
max1 = 0
min1 = 9
For i = 1 To Len(p)
s = Val(Mid(p, i, 1))
If s >= max1 Then max1 = s
If s <= min1 Then min1 = s
Next i
If Val(min1) = 0 Then min1 = ""
n = min1 & max1
List1.AddItem n
For i = 0 To List1.ListCount - 2
If List1.List(List1.ListCount - 1) = List1.List(i) Then
Print #2, "*" & n & " " & n ^ 2
Exit Do
End If
Next i
Loop
Close #2
Close #1
End
End Sub