Sunday 20 October 2013

Armstrong number in C

#include <stdio.h>
void main()
{
int n,x,temp,sum=0;;
printf("enter the number:");
scanf("%d",&n);
   x=n;
while(n!=0)
{
         temp=n%10;
sum=sum + temp * temp * temp;
n=n/10;
}
if(x==sum)
printf("number is armstrong");
else
  printf("number is not armstrong");
}

No comments :

Post a Comment