Friday, June 10, 2011

Check the given number is armstrong number or not using c program

#include<stdio.h>
int main(){
int num,r,sum=0,temp;
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);
return 0;
}

No comments:

Post a Comment