C# Program to check number is Armstrong or not


In this program, You will learn how to check number is Armstrong or not in C#.


Some list of armstrong numbers is: 153, 370, 371, 407

Example: How to check number is Armstrong or not in C#.

using System;
public class Program
{
	public static void Main(string[] args)
	{
		int n, num, r, rev = 0;

		Console.Write("Enter a number:");
		n = Convert.ToInt32(Console.ReadLine());

		num = n;

		while (n > 0)
		{
			r = n % 10;
			rev = rev + r * r * r;
			n = n / 10;
		}

		if (num == rev)
		{
			Console.WriteLine("Number is armstrong:" + num);
		}
		else
		{
			Console.WriteLine("Number is not armstrong:" + num);
		}
	}
}

Output:

Enter a number:153
Number is armstrong:153