Home » C Programs » C Program to Check Armstrong Number

C Program to Check Armstrong Number

This program will help you to find the number is Armstrong number or not in C.  An Armstrong three-digit number is an integer in which the total of its digits’ cubes equals the number itself. 371 is an Armstrong number, for example, since 3**3 + 7**3 + 1**3 Equals 371.

Armstrong Number

An Armstrong number, also known as a narcissistic number, is a number that equals the sum of its own digits’ cubes. 370, for example, is an Armstrong number because it equals 3*3*3 + 7*7*7 + 0*0*0.

While Loop in C

A “While” Loop is used to iterate over a specific block of code until a condition is met. The condition is evaluated first in a while loop, and if it returns true, the statements within the while loop are executed; this is repeated until the condition returns false. When the condition returns false, the control exits the loop and proceeds to the next statement in the program following the while loop. Here we have executed the c program to check armstrong number for beginners to understand the programming concepts in c.

If Else Definition in C

If a specified condition is true, the if/else statement executes a block of code. If the condition is not met, another block of code can be run. In C, the if-else statement is used to perform operations based on a specific condition. If and only if the given condition is true, the operations specified in the if block are carried out. 

C Program to Check Armstrong Number

//c program to check armstrong number 
#include <stdio.h>
int main() 
{
int num, a, rem, result = 0;
printf("Enter the number ");
scanf("%d", &num);
a = num;
while (a != 0) 
{
rem = a % 10;
result += rem * rem * rem;
a /= 10;
}
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return 0;
}

Output

Enter a three-digit integer:

456

456 is not an Armstrong number