Я пытаюсь получить целые числа "num3
" (входные данные от пользователя) и возводить в квадрат каждого символа и в конечном итоге посмотреть, включает ли его "счастливое число" = 1 или "несчастное число" 4 Например,19 - счастливое число 1 ^ 2 + 9 ^ 2 = 82, 8 ^ 2 + 2 ^ 2 = 68,6 ^ 2 + 8 ^ 2 = 100, 1 ^ 2 + 0 + 0 = 1
Sub Main()
Dim number, num2, total As Integer
Dim num3 As String
Console.Write("pick a number:")
number = Console.ReadLine()
num2 = 0
num3 = Convert.ToString(number)
Do Until total = 1 Or num2 = 4
For Each num3 In num3.Substring(0, num3.Length)
For counter = 1 To num3.Length And num3 = num3.Substring(0, num3.Length)
num2 = num3 ^ 2
total = total + num2
Console.WriteLine(total)
Next
num3 = total
Next
Loop
Console.ReadLine()
If total = 1 Then
Console.WriteLine("happy number")
ElseIf num2 = 4 Then
Console.WriteLine(number & "is a unhappy number")
Console.ReadLine()
End If
End Sub
Конечный модуль
Однако я застрял, если "num3
" заменить себя из цикла for