### Q4 write a window application in VB.NET for Armstrong number.

It is said to be an Armstrong number if and only if when we find out number’s each digit mod and cube them and add then number will be same such as the original number. The form looks like as follows:

Here textbox accept number and first it will be converted into integer number and assigned to the variable n. the code is as follows:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim n As Integer = Convert.ToInt32(TextBox1.Text)

Dim temp As Integer = n

Dim sum As Integer = 0

While (n > 0)

sum = sum + (n Mod 10) * (n Mod 10) * (n Mod 10)

n = n \ 10

End While

If (temp = sum) Then

MessageBox.Show("Number " & temp & " is armstrong")

Else

MessageBox.Show("Number " & temp & " is not armstrong")

End If

End Sub

End Class

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim n As Integer = Convert.ToInt32(TextBox1.Text)

Dim temp As Integer = n

Dim sum As Integer = 0

While (n > 0)

sum = sum + (n Mod 10) * (n Mod 10) * (n Mod 10)

n = n \ 10

End While

If (temp = sum) Then

MessageBox.Show("Number " & temp & " is armstrong")

Else

MessageBox.Show("Number " & temp & " is not armstrong")

End If

End Sub

End Class

We have made a copy of original number as temp. after that we have performed the logic inside the loop and calculated sum of each digit cube of number and assign it to the sum variable. After that we have checked that if temp= sum then number is armstrong otherwise not. The output is as follows: