SAADQUAMER

Number is Armstrong number or not

Jun 21st, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. //C program to check whether a number is Armstrong number or not.
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6. int x,sum=0,LN,num;
  7.  
  8. printf("Enter a number: ");
  9. scanf("%d",&x);
  10. num=x;
  11. while(num>0){
  12.     LN=num%10;
  13.     sum+=(LN*LN*LN);
  14.     num=num/10;
  15.     }
  16. if(sum==x)
  17.     printf("%d is an Armstrong number.",x);
  18. else
  19.     printf("%d is not an Armstrong number.",x);
  20.  
  21. return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment