Happy number:
add the square of the digits of the number. If the number you get now is equal to 1, then it is happy. If not, you continuethis process until you either get a number that is equal to 1, or you will find yourselves trapped in a sequence of numbers. For example, 19 is a happy number and the sequence looks like this:
12 + 92 = 82
82 + 22 = 68
62 + 82 = 100
12 + 02 + 02 = 1.
Also the limitation is for a number between 1 and 999.
It is a Windows Form Application with a textbox, button, and label.
The number goes into the textbox, you press the button, and then the label tells whether or not it is a happy number. Here is what I have but it is not working and I do not know where to go:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x As Integer
x = TextBox1.Text
If (TextBox1.Text <= 0) Or (TextBox1.Text >= 1000) Then
Label1.Text = "Please select a number between 1 and 999"
End If
End Sub
Private Function fun1(ByVal x As Integer) As Integer
Dim sum, y As Integer
sum = 0
Do Until sum = 1
y = x Mod 10
sum = sum + y * y
If sum = 1 Then
Label1.Text = "Happy Number"
End If
If sum <= 1 Then
Label1.Text = "Not a happy number"
End If
Loop
Return y
End Function

New Topic/Question
Reply



MultiQuote







|