Armstrong number c program

Submitted by:David Villa

Date added:13 July, 2013

Category:C

C programming code to check whether a number is armstrong or not.

Tags: armstrong number

Code Snippet:

#include <stdio.h>

int main()
{
int number, sum = 0, temp, remainder;

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

temp = number;

while( temp != 0 )
{
remainder = temp%10;
sum = sum + remainder*remainder*remainder;
temp = temp/10;
}

if ( number == sum )
printf("Entered number is an armstrong number.\n");
else
printf("Entered number is not an armstrong number.\n");

return 0;
}
 
 

Comments