21+ C# Armstrong Checker & Finder Examples

This post contains a total of 21+ Hand-Picked C Sharp Armstrong Number Checker & Finder Program Examples with Source Code. All the Armstrong Number Checker & Finder programs are made using C Sharp Programming Language.

You can use the source code of these programs for educational purpose with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By Zephyr Koo

Made by Zephyr Koo. Simple C# Program to check if a number is Armstrong or not. ( Source )

153
153 is an Armstrong number.
using System;
using System.Linq;

namespace SoloLearn
{
    class Program
    {
        static void Main(string[] zephyr_koo)
        {
            ValidateFromUserInput();
            //PopulateArmstrongNumber(10000);
        }
        
        static void ValidateFromUserInput()
        {
            var input = Console.ReadLine();
            int number;

            if (Int32.TryParse(input, out number) && number > 0)
            {
                Console.WriteLine($"{ number } is { (IsAmstrongNumber(number) ? string.Empty : "NOT ") }an Armstrong number.");
            }
        }
        
        static void PopulateArmstrongNumber(int maximum)
        {
            Console.WriteLine($"Armstrong number from 0 to { maximum }:");
            Console.WriteLine(string.Join(", ", Enumerable.Range(0, maximum).Where(n => IsAmstrongNumber(n))));
        }

        static bool IsAmstrongNumber(int number)
        {
            var strNumber = number.ToString();

            return strNumber.Sum(c => Math.Pow(Char.GetNumericValue(c), strNumber.Length)) == number;
        }
    }
}

2. By Mickel

Made by Mickel. Program to check whether a given number is an Armstrong number or not. This program also prints all the armstrong numbers in that range. ( Source )

This program shows all Armstrong Numbers in a range of 1 to n.

In the range from 1 to 999 there are the following Armstrong Numbers:
1 2 3 4 5 6 7 8 9 153 370 371 407 

NOTE: 999 isn't a Armstrong number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
		    int number;
		    
			Console.WriteLine("This program shows all Armstrong Numbers in a range of 1 to n.");
			Console.WriteLine();
			
			number = int.Parse(Console.ReadLine());
		    
		    Console.WriteLine("In the range from 1 to {0} there are the following Armstrong Numbers:", number);
		    
		    for(int n = 1; n <= number; n++) {
		        if (ArmstrongNumber(n)) {
		            Console.Write("{0} ", n);
		        }
		    }
		    
		    Console.WriteLine("\n\nNOTE: {0} {1} a Armstrong number.", number, ArmstrongNumber(number) ? "is" : "isn\'t");
		}
		
		static bool ArmstrongNumber(int num) {;
		    int remainder;
		    int sum = 0;
		    int pow = (int) Math.Floor(Math.Log10(num) + 1);
		    
		    for (int i = num; i > 0; i /= 10) {
		        remainder = i % 10;
		        sum += (int) Math.Pow(remainder, pow);
		    }
		    
		    if (sum == num) {
		        return true;
		    }
		    
		    return false;
		}
	}
}

3. By Julia Shabanova

Made by Julia Shabanova. C# Armstrong checker program. ( Source )

370
370 is an Armstrong number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            int sum = 0;
            string b = Console.ReadLine();
            int len = b.Length;
            int num = Convert.ToInt32(b);
                     
            for (int i=len; i> 0;i--)
            {sum += Convert.ToInt32(Math.Pow(num%10, len));
             num = num/10;}
            
            if (sum == Convert.ToInt32(b))
            {Console.Write(b + " is an Armstrong number");}
            else
            {Console.Write(b + " isn't an Armstrong number");}           
        }
    }
}

4. By David Carroll

Made by David Carroll. Checks if the numbers in a string are Armstrong or not. Change the input numbers in the line ‘ string[] inputs = {“-1”, “abc”, “3”, “153”, “12”, “1634” }; ( Source )

False
False
True
True
False
True

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;


namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
		    //An Armstrong Number is equal to the sum of the cubes of its digits.
		    
            string[] inputs = {"-1", "abc", "3", "153", "12", "1634" };
            //string[] inputs = Console.In.ReadToEnd().Split('\n');
            
            (from input in inputs select input.All(Char.IsNumber) ? input : "10").ToList()
            	.ForEach( input => Console.WriteLine(
            		input.Select(digit => uint.Parse(digit.ToString()))
            		.Sum(digit => Math.Pow(digit, input.Length))
            		.Equals(ulong.Parse(input))
            	));
		}
	}
}

5. By David Carroll

Another C# Armstrong number checker program by David Carroll. ( Source )

9 is an Armstring Number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;


namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
		    // NOTE: Constraints not yet implemented.
		    
            string input = Console.ReadLine();
            
            var isvalid = input.Select(digit => int.Parse(digit.ToString()))
            			  .Sum(digit => Math.Pow(digit, input.Length))
            			  .Equals(int.Parse(input));
            			  
            Console.WriteLine("{0} is{1} an Armstring Number.", input, isvalid ? "" : " not");
		}
	}
}

6. By ChillPill ๐ŸŒถ

Made by ChillPill ๐ŸŒถ. ( Source )

Enter a number: 
You entered 370
1 is an armstrong number.
2 is an armstrong number.
3 is an armstrong number.
4 is an armstrong number.
5 is an armstrong number.
6 is an armstrong number.
7 is an armstrong number.
8 is an armstrong number.
9 is an armstrong number.
153 is an armstrong number.
370 is an armstrong number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            
            int num;
            Console.WriteLine("Enter a number: ");
            num = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("You entered {0}", num);
            for(int i=1;i<=num;i++){
                checkarmstrongnumber(i);
            }
            //checkarmstrongnumber(num);
        }
        static void checkarmstrongnumber(int x){
            string mynumber = x.ToString();
            int count = mynumber.Length ;
            char digyt;
            int total = 0;
            for(int i = 0; i<count; i++){
                digyt = mynumber[i];
                int powar = 1;
                for(int y = 1; y <=count; y++){
                    powar *= ((int)(digyt-'0'));
                }
                total += powar;
                
            }
            if(total == x){
                Console.WriteLine(total + " is an armstrong number.");
            }
        }
    }
}

7. By Vishal Panchal

Made by Vishal Panchal. ( Source )

Enter the number: 765
Not an Armstrong Number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication6{

   class Program{
    
      static void Main(string[] args){
        
        int number, remainder, sum=0;
            
        Console.Write("Enter the 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("Is an Armstrong Number");
          else
             Console.Write("Not an Armstrong Number");
                
             Console.ReadLine();
        }
    }
}

8. By M Rashid Khan

Made by M Rashid Khan. This C# Program is written to Check Whether the Entered Number is an Armstrong Number or Not . ( Source )

enter the Number: 371
Entered Number is an Armstrong Number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{     
	class Program
	{
		static void Main(string[] args)
        {
            int number, remainder, sum = 0;
            Console.Write("enter the 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("Entered Number is an Armstrong Number");
            }
            else
                Console.Write("Entered Number is not an Armstrong Number");
            Console.ReadLine();
        }
	}
}

9. By Sumit Patil

Made by Sumit Patil. ( Source )

Enter number
444 is not Armstrong number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            int num,num1,cal=0,temp;
            Console.WriteLine("Enter number");
           num=int.Parse(Console.ReadLine());
            temp=num;
            while(temp>0)
            {
                num1=temp%10;
                cal=cal+num1*num1*num1;
                temp=temp/10;
            }
            if(cal==num)
              Console.WriteLine(num+" is Armstrong number");
            else 
              Console.WriteLine(num+" is not Armstrong number");
            
        }
    }
}

10. By Derek Stan G. Apostol

Made by Derek Stan G. Apostol. The program will find and print all the Armstrong number between a input range. ( Source )

1
10000
1 is an Armstrong Number
2 is an Armstrong Number
3 is an Armstrong Number
4 is an Armstrong Number
5 is an Armstrong Number
6 is an Armstrong Number
7 is an Armstrong Number
8 is an Armstrong Number
9 is an Armstrong Number
153 is an Armstrong Number
370 is an Armstrong Number
371 is an Armstrong Number
407 is an Armstrong Number
1634 is an Armstrong Number
8208 is an Armstrong Number
9474 is an Armstrong Number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
        /*Input lowest then highest*/
            double o=Convert.ToDouble(Console.ReadLine());
            double p=Convert.ToDouble(Console.ReadLine());
            for(;o<p;o++)
            {
                string str = Convert.ToString(o);
                int length = str.Length;
                double[] number = new double[length];
                for(int x=0;x<length;x++)
                {
                    number[x]=Math.Pow((str[x]-48),length);
                }
                double w=number.Sum();
                if(w==Convert.ToDouble(str))
                {
                    Console.WriteLine("{0} is an Armstrong Number",str);
                }
            }
        }
    }
}

11. By Eugene Nefedov

Made by Eugene Nefedov. Program to find Armstrong numbers between a given range. Enter the range in line   for (int i=100; i<1000; ++i) ( Source )

153
370
371
407
using System;  
class Programm{ 
    
    static void Main ()
        {
         
        for (int i=100; i<1000; ++i)
        { 
        int x = i/100;   
        int y = i%100/10;   
        int z = i%10;   
        int q = (int) Math.Pow(x,3) + (int) Math.Pow(y,3) + (int) Math.Pow(z,3);  
        if (q==i) 
            Console.WriteLine(q);
        }
   } 
}

12. By Derek Stan G. Apostol

Another program by Derek Stan G Apostol to check if a given number is Armstrong or not. ( Source )

153
153 is an Armstrong number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int length = str.Length;
            double[] number = new double[length];
            for(int x=0;x<length;x++)
            {
                number[x] = Math.Pow(str[x]-48,length);
            }
            double w=(number.Sum());
            if (w==Convert.ToDouble(str))
            {
                Console.WriteLine("{0} is an Armstrong number",str);
            }
            else
            {
                Console.WriteLine("Nah");
            }
        }
    }
}

13. By Shashank

Made by Shashank. Program to check Armstrong Number. ( Source )

Enter the Number= 123
123 Not Armstrong Number.
using System;  
  public class Program
   {  
     public static void Main(string[] args)  
      {  
       int  n,r,sum=0,temp;      
             
       n= int.Parse(Console.ReadLine());     
       Console.Write("Enter the Number= "+n);
       temp=n;      
       while(n>0)      
       {      
        r=n%10;      
        sum=sum+(r*r*r);      
        n=n/10;      
       }      
       if(temp==sum)      
        Console.Write(" Armstrong Number.");      
       else      
        Console.Write(" Not Armstrong Number.");      
      }  
  }  

14. By Sumit Pandey

Made by Sumit Pandey. ( Source )

124
No
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int rem,rev=0,temp=n;
            while(temp>0)
            {
                rem=temp%10;
                rev=rev+rem*rem*rem;
                temp/=10;
            }
            
             if (rev==n)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

15. By Kevin O’ Sullivan

Made by Kevin O’ Sullivan. Checks if a user supplied number is an Armstrong number. ( Source )

Please enter a 3-digit number: 
371 is an Armstrong number!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Armstrong
    {
        static void Main(string[] args)
        {
            
            Console.WriteLine("Please enter a 3-digit number: ");
            string num = Console.ReadLine();
            
            int n1 = Convert.ToInt32(Convert.ToString(num[0]));
            int n2 = Convert.ToInt32(Convert.ToString(num[1]));
            int n3 = Convert.ToInt32(Convert.ToString(num[2]));
            
            if(Math.Pow(n1,3) + Math.Pow(n2,3) + Math.Pow(n3,3) == Convert.ToInt32(num))
            {
                Console.WriteLine("{0} is an Armstrong number!",num);
            }
            else
            {
                Console.WriteLine("{0} is not an Armstrong number...",num);
            }
        }
    }
}

16. By Raza Haider

Made by Raza Haider. Program to print out all Armstrong numbers between 1 and 500. ( Source )

All Amstrong Numbers: 

Amstrong Number: 1
Amstrong Number: 153
Amstrong Number: 370
Amstrong Number: 371
Amstrong Number: 407
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
             Console.WriteLine("All Amstrong Numbers: \n");
             
             int d1, d2, d3;
             int num = 001;
             int temp;
             
             while(num <= 500)
             {
                 d1 = num - ((num / 10) * 10);
                 d2 = (num / 10) - ((num / 100) * 10);
                 d3 = (num / 100) - ((num / 1000) * 10);
                 temp = (d1 * d1 * d1) + (d2 * d2 * d2) + (d3 * d3 * d3);
                 
                if(temp == num)
                    Console.WriteLine("Amstrong Number: "+ temp);
                    
                num++;    
             }

			
		}
	}
}

17. By Hans Larry

Made by Hans Larry. ( Source )

407
ArmStrong number
using System;

public class Test
{
	public static void Main()
	{
		int x=Convert.ToInt32(Console.ReadLine());
		double top=0;
		string st=x.ToString();
		
		string ch;
		for (int i=0; i<st.Length; i++)
		{
	ch=st [i].ToString();	
	top+=Math.Pow(Convert.ToInt32(ch),st.Length);
	  }
	  if (top==x)
		Console.WriteLine("ArmStrong number"); else
		Console.WriteLine("Not ArmStrong number");
	}
}

18. By Tyrone Kruger

Made by Tyrone Kruger. ( Source )

You entered 69 and it is not an Armstrong number. 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn{

    class Program{
    
        static void Main(string[] args){
            var n=Convert.ToInt32(Console.ReadLine());
            Console.Write("You entered {0} and it is{1}an Armstrong number.",n,(stro(n))?" ":" not ");
        }
        static bool stro(int x){
            int sum=0;
            foreach(char c in Convert.ToString(x)){
                sum+=(c-'0')*(c-'0')*(c-'0');
            }
            return sum==x;
        }
    }
}

19. By Silvio Duka

Made by Silvio Duka. C# program that finds all the Armstrong numbers that are between a given range. ( Source )

The number 153 is an Armstrong number.
The number 370 is an Armstrong number.
The number 371 is an Armstrong number.
The number 407 is an Armstrong number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArmstrongNumberMedium
{
    class Program
    {
        static void Main(string[] args)
        {
            int nFrom = 100; // Set a start number of range
            int nTo = 999; // Set a end number of range

            for (int number = nFrom; number <= nTo; number++)
            {
                int armstrong = 0;
                int t = number;

                while (t != 0)
                {
                    armstrong += (int)Math.Pow(t % 10, 3);

                    t = t / 10;
                }

                if(number == armstrong) Console.WriteLine($"The number {number} is an Armstrong number.");
            }
        }
    }
}

20. By Sumit Pandey

Made by Sumit Pandey. ( Source )

92 is not Armstrong number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            
        int n = Convert.ToInt32(Console.ReadLine());
            int rem,sum=0;
            int temp =n;
            while(temp>0)
            {
                rem = temp%10;
                sum = rem*rem*rem+sum;
                temp/=10;
            }
            
            if (n==sum)
            {
                Console.WriteLine("{0} is Armstrong number.", sum);
            }
            else
            {
                Console.WriteLine("{0} is not Armstrong number.", sum);
            }
        }
    }
}

21. By vaidyanathan s

Made by vaidyanathan s. ( Source )

Armstrong  Number
------------------------------
Enter the Start Number : 1 

Enter the End Number : 999 

Inputs between 1 and 999 are : 
1
2
3
4
5
6
7
8
9
153
370
371
407
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
    /* int StartNumber;
        
        int EndNumber;*/
        static void Main(string[] args)
        {
       Console.Write("Armstrong  Number\n");
       Console.Write("------------------------------\n");
    
            Console.Write("Enter the Start Number :");

int StartNumber = int.Parse(Console.ReadLine());
Console.WriteLine($" {StartNumber} \n");

Console.Write("Enter the End Number :");

int EndNumber = int.Parse(Console.ReadLine());
Console.WriteLine($" {EndNumber} \n");
Console.WriteLine($"Inputs between {StartNumber} and {EndNumber} are : ");

for (int i = StartNumber; i <= EndNumber; i++)

{

if (IsArmstrongNumber(i))

Console.WriteLine(i);

}

Console.ReadLine();

}

static bool IsArmstrongNumber(int number)

{

int sum = 0;

int temporaryNumber = number;

int temp = 0;

int length = number.ToString().Length;

while (number != 0)

{

temp = number % 10;

number = number / 10;

sum += (int)Math.Pow(temp, length);

}

if (sum == temporaryNumber)

{

return true;

}

else

{

return false;

}


        }
    }
}

22. By Rajvi Sarvaiya

Made by Rajvi Sarvaiya. Program to find if a number is Armstrong or it is not. ( Source )

371 is an Armstrong number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            //get the addition of cubes
            int sum=0,x;
            for(int i =n;i>0;)
            {
                x=i%10;
                sum = sum + (x*x*x);
                i=i/10;
            }
            //if sum is same as n then itis armstrong no
            if(sum == n)
            Console.Write("{0} is an Armstrong number.",n);
            else
            Console.Write("{0} is not an Armstrong number.",n);
        }
    }
}