Armstrong Number solution using c language programming info problem 18

Armstrong Number



  1. 153 = (1*1*1)+(5*5*5)+(3*3*3)  
  2. where:  
  3. (1*1*1)=1  
  4. (5*5*5)=125  
  5. (3*3*3)=27  
  6. So:  
  7. 1+125+27=153  





  1. #include<stdio.h>  
  2.  int main()    
  3. {    
  4. int n,r,sum=0,temp;    
  5. printf("enter the number=");    
  6. scanf("%d",&n);    
  7. temp=n;    
  8. while(n>0)    
  9. {    
  10. r=n%10;    
  11. sum=sum+(r*r*r);    
  12. n=n/10;    
  13. }    
  14. if(temp==sum)    
  15. printf("armstrong  number ");    
  16. else    
  17. printf("not armstrong number");    
  18. return 0;  
  19. }   
  20. Output:
  21. enter the number=153
    armstrong number
    
    enter the number=5
    not armstrong number
Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support