Write a program to find all Armstrong number in the entered range
An integer number is called Armstrong number if sum of the cubes of its digits is equal to the number itself.
Checking for the Armstrong numbers, print the result on the output screen as shown here in the following program.
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 28 29 |
static void Main(string[] args) { int num1,num2, n, sum, r; Console.Write("Enter positive number1 :"); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter positive number2 :"); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Armstrong Number from {0} to {1}",num1,num2); for (int i = num1; i <= num2; i++) { sum = 0; n = i; while (n != 0) { r = n % 10; sum = sum + (r * r * r); n = n / 10; } if (i == sum) Console.WriteLine(i); } Console.ReadKey(); } |