What is Armstrong Number?
Armstrong number is a number that is equal of sum of cubed of its digits.as a example - 153= 13 + 53 + 33 =1+125+27=153
Source Code:
- # include <stdio.h>
- int main()
- {
- int temp,n,sum=0,x;
- printf("Enter the number: ");
- scanf("%d",&x);
- temp=x;
- while(temp>0)
- {
- n=temp%10;
- sum=sum+(n*n*n);
- temp=temp/10;
- }
- if(sum==x)
- printf("\n It is an anstrong number!!!");
- else
- printf("\n It is not an anstrong number!!!");
- return 0;
- }
Output:
Enter the number: 153
It is an anstrong number!!!
Enter the number: 123
It is not an anstrong number!!!
0 comments:
Post a Comment