LarvitarYoung

ArmstrongNumber

Nov 6th, 2021 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int power(int base,int exponent){
  4.     int dependant=base;
  5.     if(exponent<1){return 1;}
  6.     for(int i=1;i<exponent;i++){
  7.         dependant*=base;
  8.     }
  9.     return dependant;
  10. }
  11. void main(int argc, char const *argv[]){
  12.     int sum=0,input;
  13.     scanf("%d",&input);
  14.     int NumOfDigits =  ceil(log10(input))==floor(log10(input)) ? ceil(log10(input))+1 : ceil(log10(input));
  15.     for (int i = 0; i < NumOfDigits; i++){
  16.         sum+=power((input/power(10,i)%10),NumOfDigits);
  17.     }
  18.     if(sum==input){printf("is armstrong number");}
  19.     else{printf("it's not");}
  20. }
  21.  
Add Comment
Please, Sign In to add comment