Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- int power(int base,int exponent){
- int dependant=base;
- if(exponent<1){return 1;}
- for(int i=1;i<exponent;i++){
- dependant*=base;
- }
- return dependant;
- }
- void main(int argc, char const *argv[]){
- int sum=0,input;
- scanf("%d",&input);
- int NumOfDigits = ceil(log10(input))==floor(log10(input)) ? ceil(log10(input))+1 : ceil(log10(input));
- for (int i = 0; i < NumOfDigits; i++){
- sum+=power((input/power(10,i)%10),NumOfDigits);
- }
- if(sum==input){printf("is armstrong number");}
- else{printf("it's not");}
- }
Add Comment
Please, Sign In to add comment