Facebook Google Plus YouTube

C program to check a number is Armstrong number or not.

C program to check a number is Armstrong number or not.

Armstrong Number:
A number is refer as Armstrong number if the numbers each digits cubic sum is equivalent to that number.
Example: 153 = (1)^3 + (5)^3 + (3)^3.

C program:

#include <stdio.h>
int main()

{

int number,i,j,sum,reminder,tempo;
printf("Enter a number\n");
scanf("%d",&number);

tempo =number;
sum=0;
while(number != 0)
{
reminder = number%10;
sum=sum+(reminder*reminder*reminder);
number=number/10;
}
if(sum==tempo)
{
printf("%d is a armstrong number\n",tempo);
}
else
{
printf("%d is not a armstrong number\n",tempo);
}
return 0;
}

OUTPUT:

Enter a number:

153

153  is a armstrong number.

Leave a Reply

%d bloggers like this: