Write a c program to Check whether a number is a AMSTRONG NUMBER or not.
source code:
- #include<stdio.h>
- void main()
- {
- int n,sum=0,digit,t;
- printf("Enter any integer number:");
- scanf("%d",&n);
- t=n;
- while(n!=0)
- {
- digit = n%10;
- sum = sum + digit * digit * digit;
- n=n/10;
- }
- //printf("The sum of its digit is:%d\n",sum);
- printf("\n");
- if(sum==t)
- printf("It is an Amstrong number.");
- else
- printf("It is not an Amstrong number.");
- }
Output:
1st example:
Enter any integer number:371
It is an Amstrong number.
2nd example:
Enter any integer number:125
It is not an Amstrong number.
0 comments:
Post a Comment