Learn about C program to check Armstrong number in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
C program to check Armstrong number
The below C program takes a number as user input and tests whether it is a Armstrong number.
Program:
#include<stdio.h>
int main()
{
int number, temp, rem, sum=0;
printf("Enter number: ");
scanf("%d",&number);
temp=number;
while( number!=0 )
{
rem = number%10;
sum += (rem*rem*rem);
number /= 10;
}
if(temp == sum)
printf("%d is an Armstrong number.\n",temp);
else
printf("%d is not an Armstrong number.\n",temp);
return 0;
}
Output:
Enter number: 153
153 is an Armstrong number.
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
C program to find the perfect number using the Function
C program to check Perfect Number in a given Range