Skip to content
Home » C Programs » C Program to Check Armstrong Number Using For Loop

C Program to Check Armstrong Number Using For Loop

Basic c program to check armstrong number using for loop. Using this program we can check the number as an armstrong number using a looping statement for beginners.

Armstrong Number Definition

The sum of the cubes of its own digits is equal to an Armstrong number, also known as a narcissistic number. An Armstrong three-digit number is an integer in which the total of its digits’ cubes equals the number itself.

For Loop Definition in C

In the C programming language, the for loop is used to iterate statements or parts of a program numerous times. It is commonly used to traverse data structures such as an array and a linked list. 

A for-loop (or simply for loop) is a control flow statement in computer science that specifies iteration and allows code to be executed repeatedly. When the number of iterations is known before entering the loop, for-loops are commonly used. Using this looping statement we have executed the c program to check armstrong number using for loop

C Program to Check Armstrong Number Using For Loop

//c program to check armstrong number using for loop
#include <stdio.h>
void main()
{
int num,r,sum=0,temp;
printf("Enter The Number \n");
num = 153;
for(temp=num;num!=0;num=num/10)
{
r=num % 10;
sum=sum+(r*r*r);
}
if(sum==temp)
printf("%d is an Armstrong Number\n",temp);
else
printf("%d is not an Armstrong Number\n",temp);
}

Output:

Enter The Number
153 is an Armstrong Number