Saturday, April 18, 2009

Chech the given no is amstrong or not+

void main()
{
int num,r,sum=0,temp;
clrscr();
printf("\nEnter a number:-");
scanf("%d",&num);
temp=num;
while(num!=0)
{
r=num%10;
num=num/10;
sum=sum+(r*r*r);
}
if(sum==temp)
printf("\nThe number %d is an armstrong number",temp);
else
printf("\nThe number %d is not an armstrong number",temp);
getch();
}

0 comments: