# Find Armstrong Number C Program

## C Program To Find Armstrong Number

Here’s a C Program To Find Armstrong Numbers. Learn How To Check if a Number is an Armstrong Number or not in C Programming Language. It is important that we should know How A For Loop Works before getting further with the C Program Code.

#### What is an Armstrong Number?

If the Sum of Cubes of Individual Digits of an Integer is equivalent to the Integer, then it can be regarded as an Armstrong Number. Armstrong Number is similar to a Narcissistic Number.

#### Example

153 = (1 * 1 * 1) + (5 * 5 * 5) + (3 * 3 * 3)
371 = (3 * 3 * 3) + (7 * 7 * 7) + (1 * 1 * 1)

We have written 3 different variants to Check Armstrong Integers in C Programming Language which includes While Loop, For Loop and Functions.

#### How does this program work?

1. The original number is copied into a temporary variable
2. The last digit of the original number is extracted and cubed and added in the sum variable.
3. The last digit is extracted till the original number is not equal to zero.
4. After extraction and cubing, the sum variable is compared with the temporary variable.
5. If sum == temp, Number is an Armstrong Number, else it is not an Armstrong Integer.

#### Output

In case you get any Compilation Errors or any doubts in this C Program To Find Armstrong Number, let us know about it in the Comment Section below.

Recommended Programs
C Program To Check if a Number is Magic Number or Not
C Program To Add Two Numbers without Arithmetic Operator
C Program To Find Perfect Numbers
C Program To Check Narcissistic Number
C Program To Check Palindrome Numbers
C Program To Print Hello World Without Semi Colon
Code To Remove Vowels in a String in C Programming
Find Smallest Digit in a Number C Program
C Program To Check Leap Year
100+ C Programs For Programming Interviews

#### Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

### 26 thoughts on “Find Armstrong Number C Program”

• November 29, 2015 at 4:53 pm

Thanks! It works perfect!

• November 12, 2016 at 8:43 am

If input is 10 output is ten Armstrong numbers

• May 28, 2016 at 11:22 am

Wow. Thanks for so many armstrong number programs in different ways. This has made my work more easier.

• July 29, 2016 at 12:33 am

I am getting confused in void main and int main. The armstrong number programs that are here jave int main() declarations. Is it compulsory to use them?

• July 29, 2016 at 12:48 am

Hi Pankaj! int main() is primarily used when you want to fetch arguments using Command Line. Otherwise, void main() will work. This Armstrong Number C Programs above can be made to work through command line by adding two arguments in the main function. (int argc, int *argv).

• July 29, 2016 at 12:46 am

In this Armstrong Integer Program, I am getting confused with the modulus operator. Can you help me understand the use of Modulus Operator?

• July 31, 2016 at 1:01 pm

This is just awesome. So many ways to write armstrong number program in c! It helped me to clear my concepts functions and also how to convert for loop into while loop.

• August 20, 2016 at 2:44 pm

So many methods have made my basics clear about Armstrong Numbers and C programming looping system. I have a doubt. When we enter three numbers, the program shows correct output, but if the number consists of more than 4 digits, it shows a wrong output.

• August 20, 2016 at 2:47 pm

Hi Piyu. Armstrong Number program calculates only upto 3 digits. If you want to find armstrong number more than 3 digits, you should check its big brother Narcissistic Number. The Narcissistic Numbet C Program link is given in the above program.

• August 21, 2016 at 12:45 am

• August 21, 2016 at 12:46 am

Hi Rajendra. Well, the float variables cannot be used an an operand with Modulus Operator. That is why you would be getting errors. Please check which datatypes work with Modulus Operator and then select a suitable datatype.

• August 29, 2016 at 2:35 pm

You have executed this Armstrong Number C Program in Linux. Is it compatible if I execute it on Windows platform?

• September 10, 2016 at 3:08 am

Yes. This Armstrong Integer code is written in Linux without any IDE. There should not be any problem to run this code on Windows platform.

• September 8, 2016 at 3:28 pm

Why not use Recursion to calculate Armstrong Numbers,

• September 10, 2016 at 3:08 am

Yes. You may use Recursive function also to find solution to Armstrong Number problem.

• September 10, 2016 at 3:05 am

I think the condition num!=0 can also be changed to num>0 or num>=1 in this code.

while(num1 != 0)
{
rem = num1%10;
sum = sum + (rem*rem*rem);
num1 = num1/10;
}

• September 10, 2016 at 3:06 am

Yes. Your code will work perfectly fine in finding armstrong integers.

• September 13, 2016 at 10:09 pm

Why do we need to copy the armstrong number variable num1 into temp? I also see that the sum variable os compared to temp. Why can’t we compare it to num1 variable?

• October 3, 2016 at 10:06 pm

How do I cube the remainder variable? Is there a built in function for it or do we have to make a user defined function?
for(temp = num1; num1 != 0;)
{
rem = num1%10;
sum = sum + cube(rem);
num1 = num1/10;
}

• October 4, 2016 at 12:31 am

` int cube(int a, int b, int c) { int r = a*b*c; return r; } `

• November 5, 2016 at 1:58 pm

The narcissistic number code is much better than just an Armstrong number code. The armstrong number code can find the cubes only upto 3 digits and what after that? On the other hand, the narcissistic number is an advanced version of the armstrong number which can calculate cubes of numbers having more than 3 digits.

• November 12, 2016 at 8:40 am

Can we get possible number of Armstrong numbers within a range? Ex,if input is 10 ,10 Armstrong numbers should be output?