How to Get Armstrong Numbers Between 1 to 1000 in VB.Net

If you wonder how to get Armstrong numbers in VB.Net, simply follow the procedure below to see if a number is an Armstrong number. But, before that let’s learn first what Armstrong number is? Is a number that when you raise each digit of the number to the power of the number of digits and add them up you still get the original number. It will be easier with an example, take a look at this. For example, 153 is an Armstrong number since (1^3) + (5^3) + (3^3) =153.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application. psArmstrong

Step 2

Do the Form just like this. formArmstrong

Step 3

Go to the code view and make a function for getting the Armstrong numbers.
  1. Public Function displayArmstrongNumbers()
  2. Dim i, num As Integer
  3. Dim res As Integer
  4. Dim s As Integer
  5.  
  6. For i = 2 To 1000
  7. num = i
  8. s = 0
  9. While num > 0
  10. res = num Mod 10
  11. s = s + (res * res * res)
  12. num = num \ 10
  13. End While
  14. If i = s Then
  15. Return i
  16. End If
  17. Next
  18. Return displayArmstrongNumbers()
  19. End Function

Step 4

Do the following code to display the Armstrong number in the message box when the button is clicked.
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. MsgBox(“Armsrtong Numbers betwwen 1 To 1000 are : ” & displayArmstrongNumbers())
  3. End Sub
For any questions about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT Or feel free to comment below.

Add new comment