To check whether a number is an Armstrong number or not an Armstrong number in C# programming language.
An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.
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: