Let’s write a C# program to check whether the given number is armstrong number or not.
Armstrong Number in Java: A positive number is called armstrong number if it is equal to the sum of cubes of its digits for example 0, 1, 153, 370, 371 etc.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
static void Main(string[] args) { int n, nu, num = 0, rem; Console.Write("Enter positive number :"); n = Convert.ToInt32(Console.ReadLine()); nu = n; while (nu != 0) { rem = nu % 10; num = num + rem * rem * rem; nu = nu / 10; } if (num == n) { Console.WriteLine("Armstrong Number"); } else { Console.WriteLine("Not Armstrong Number"); } Console.ReadLine(); } |
Output: