What is Armstrong Number?

Armstrong is a number that is equal to the sum of the cubes.For Ex-153,370,0,1

The c# program to check Number is Armstrong or Not.

using System; class Program { static void Main(string[] args) { int number, remainder, sum = 0, temp; Console.Write("Enter a number : "); number = int.Parse(Console.ReadLine()); temp = number; while(number>0) { remainder = number% 10; sum = sum + remainder*remainder*remainder; number = number / 10; } if (sum == temp) { Console.Write(sum + " is an Armstrong number."); } else Console.Write(sum +" is not an Armstrong number."); Console.ReadLine() } }

In VB.Net program to check Number is Armstrong or Not.

Advertisement

Imports System Class Program Private Shared Sub Main(args As String()) Dim number As Integer, remainder As Integer, sum As Integer = 0, temp As Integer Console.Write("Enter a number : ") number = Integer.Parse(Console.ReadLine()) temp = number While number > 0 remainder = number Mod 10 sum = sum + remainder * remainder * remainder number = number \ 10 End While If sum = temp Then Console.Write(sum & " is an Armstrong number.") Else Console.Write(sum & " is not an Armstrong number.") End If Console.ReadLine() End Sub End Class

Advertisement