Q. C# program to check whether the given number N is Armstrong number or not.
Here you will find an algorithm and program in C# programming language to check whether the given number N is Armstrong number or not. First let us understand what is Armstrong number
Explanation : A Armstrong Number is a number that is equal to sum of cubes of each digits.
For Example : 153. So as we can see that the sum of cubes of each digit (1^3=1, 5^3=125, 3^3=27 => 1+125+27=153) is equal to it's number. So 153 is an Armstrong number.
Armstrong Number Algorithm
START step 1 : read number step 2 : set sum=0 and duplicate=number step 3 : reminder=number%10 step 4 : sum=sum+(reminder*reminder*reminder) step 5 : number=number/10 step 6 : repeat steps 4 to 6 until number > 0 step 7 : if sum = duplicate step 8 : display number is armstrong step 9 : else step 10 : display number is not armstrong STOP
C# Program To Check Armstrong Number
using System; public class LFC { public static void Main(string[] args) { int n,r,sum=0,temp; n= 153; temp=n; while(n>0) { r=n%10; sum=sum+(r*r*r); n=n/10; } if(temp==sum) Console.Write("The number "+temp+" is Armstrong Number."); else Console.Write("The number "+temp+" is Not Armstrong Number."); } }
Output
The number 153 is an Armstrong number.