Armstrong Number in C | A C Program to Find Armstrong Number

Armstrong Number - An Armstrong Number is a Number which is equal to it’s sum of digit’s cube. For example - 153 is an Armstrong number: here 153 = (1*1*1) + (5*5*5) + (3*3*3).

This program will read an integer number and check whether it is Armstrong Number or Not, to check Armstrong number, we have to calculate sum of each digit’s cube and then compare number is equal to Sum or not. If Number and Sum of digit’s cube then Number will be an Armstrong Number otherwise not.

Check Armstrong Number using C program

﻿

```/* C program to check whether a number is armstrong or not */

#include <stdio.h>

int main()
{
int number, sum=0, rem=0,tempNumber;

printf("Enter an integer number: ");
scanf("%d", &number);

tempNumber=number;

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

/* checking number is armstrong or not */
if(sum==number)
printf("%d is an Armstrong number.",number);
else
printf("%d is not an Armstrong number.",number);

return 0;
}
```

Using User Define Function

﻿

```/* C program to check whether a number is armstrong or not */

#include <stdio.h>

/*function to check Armstrong Number*/
int isArmstrong(int num)
{
int tempNumber=num;
int rem,sum;

/*sum of digit's cube*/
sum=0;
while(tempNumber!=0)
{
rem=tempNumber%10;
sum=sum + (rem*rem*rem);
tempNumber/=10;
}

if(sum==num)
return 1;   /*Armstrong Number*/
else
return 0;   /*Not an Armstrong Number*/
}

int main()
{
int number;

printf("Enter an integer number: ");
scanf("%d", &number);

if(isArmstrong(number))
printf("%d is an Armstrong number.",number);
else
printf("%d is not an Armstrong number.",number);

return 0;
}
```

Output

```    First run:
Enter an integer number: 153
153 is an Armstrong number.

Second run:
Enter an integer number: 167
167 is not an Armstrong number.
```

TOP Interview Coding Problems/Challenges

Learn PCB Designing: PCB DESIGNING TUTORIAL

 Recommended posts C Tips & Tricks, C++ Tips & Tricks Introduction to Linux (Its modes, Safety, Most popular Applications) Linux Best Distros of 2018 C programming optimization techniques Differences b/w C & Embedded C? Embedded C Interview Q. & A. C programming tips for Embedded Development Basic rules of writing a C program Important points (rules) to remember while writing C/C++ program Top 5 Websites for solving programming challenges Read more...

 Others... Computer G.K. (MCQ) Most viewed pages... Categories...

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates