3️⃣C Program to Check Armstrong Number (With Program and Explanation)

 

C Program to Check Armstrong Number+

What is an Armstrong Number?

An Armstrong number is a number in which the sum of its digits raised to the power of the total number of digits is equal to the original number.

Example:
153 → 1³ + 5³ + 3³ = 153


Algorithm

  1. Read a number from the user

  2. Count the number of digits

  3. Calculate the sum of each digit raised to the power of digits

  4. Compare the sum with the original number

  5. Display the result


C Program

#include <stdio.h> #include <math.h> int main() { int number, originalNumber; int digit, digits = 0; int sum = 0; printf("Enter a number: "); scanf("%d", &number); originalNumber = number; /* Count number of digits */ while (originalNumber != 0) { originalNumber = originalNumber / 10; digits++; } originalNumber = number; /* Calculate Armstrong sum */ while (originalNumber != 0) { digit = originalNumber % 10; sum = sum + pow(digit, digits); originalNumber = originalNumber / 10; } /* Check Armstrong number */ if (sum == number) printf("%d is an Armstrong Number.", number); else printf("%d is not an Armstrong Number.", number); return 0; }

Sample Output

Enter a number: 153 153 is an Armstrong Number.

Conclusion

This C program checks whether a given number is an Armstrong number. It works for numbers of any length and helps beginners understand loops, conditions, and mathematical functions in C


📘 C Programming Series – What’s Next?

👉 In the next post of this series, we will learn how to write a C Program to Check Palindrome Number, with complete explanation and output examples. Stay tuned! 🚀


Comments

Popular posts from this blog

⓮C Program to calculate Simple Interest (With Program and Explanation)

⑫ C Program to Swap Two Numbers Without Using a Temporary Variable (With Program and Explanation)

9️⃣C Program to Find LCM of Two Numbers (With Program and Explanation)