Advertisement
Ritam_C

Armstrong number

Jan 17th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(){
  5.     int n, tmp = 0, t, d;
  6.     scanf("%d", &n);
  7.     int i = 0;
  8.     while(tmp < n){
  9.         tmp = 0;
  10.         t = n;
  11.         while(t > 0){
  12.             d = t%10;
  13.             tmp += pow(d, i);
  14.             t /= 10;
  15.         }
  16.         i++;
  17.     }
  18.  
  19.     if(tmp == n){
  20.         printf("%d is an armstrong number\n", n);
  21.     } else{
  22.         printf("%d is not an armstrong number\n", n);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement