C Program to Check Armstrong Number



A number is called as Armstrong number if sum of cubes of digits of number is equal to the number itself. In this program we will check whether a number is Armstrong or not.



  1. // C program to check Armstrong number
  2. #include <stdio.h>
  3. #include <math.h>
  4. int main()
  5. {
  6. int numb, originalNumb, r, result = 0, n = 0 ;
  7. printf("Enter an integer: ");
  8. scanf("%d", &numb);
  9. originalNumb = numb;
  10. while (originalNumb != 0)
  11. {
  12. originalNumb /= 10;
  13. ++n;
  14. }
  15. originalNumb = numb;
  16. while (originalNumb != 0)
  17. {
  18. r = originalNumb%10;
  19. result += pow(r, n);
  20. originalNumb /= 10;
  21. }
  22. if(result == numb)
  23. printf("%d is an Armstrong number.", numb);
  24. else
  25. printf("%d is not an Armstrong number.", numb);
  26. return 0;
  27. }

Output
Output!
download android app

Popular C Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube