Armstrong Program in C#
Advertisements
Armstrong Number Program in C#
To find Armstrong number program we apply same concept like C and C++ programming. Some Armstrong numbers are 153 etc.
Check Given Number is Armstrong or not in C#
using System; class Armstrong { public static void Main() { int number, remainder, sum = 0; Console.Write("Enter any Number: "); number = int.Parse(Console.ReadLine()); for (int i = number; i > 0; i = i / 10) { remainder = i % 10; sum = sum + remainder*remainder*remainder; } if (sum == number) { Console.Write("This is an Armstrong Number"); } else { Console.Write("This is not an Armstrong Number"); } Console.ReadLine(); } }
Output
Enter any Number: 153 This is an Armstrong Number
Output
Enter any Number: 133 This is not an Armstrong Number
Google Advertisment