vb.net

Armstrong Number in VB.NET

An Armstrong number is a number such that the sum of its digits raised to the third power is equal to the number itself.

Armstrong Number in VB.NET
In case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself.
For example: 153 = 1*1*1 + 5*5*5 + 3*3*3 “153 is an Armstrong number.”

Let’s see the VB.NET program to check Armstrong Number.

[php]
Imports System

Module Program
Sub Main(args As String())
Dim n As Integer, r, temp As Integer, sum As Integer = 0
Console.Write("Enter the Number= ")
n = Integer.Parse(Console.ReadLine())
temp = n

While n > 0
r = n Mod 10
sum = sum + (r * r * r)
n = n / 10
End While

If temp = sum Then
Console.Write("Armstrong Number.")
Else
Console.Write("Not Armstrong Number.")
End If
Console.ReadLine()
End Sub
End Module

[/php]

Output

armstrong-number-in-vb-net

Leave a Reply

Your email address will not be published.