If you've been exploring C programming, chances are you've come across something called an Armstrong Number. Sounds fancy, right? But don’t worry, it’s simpler than it sounds, and it's a great example to learn about logic building, loops, and conditionals in C.
In this post, we’ll explore what an Armstrong number really is, how to check for one using a C program, and why this concept helps solidify your programming fundamentals.

Explore Uncodemy’s C Programming Blog and get started today!
An Armstrong Number (also known as a narcissistic number or pluperfect number) is a number that is equal to the sum of its own digits each raised to the power of the number of digits.
Formula:
For a n digit number, an Armstrong number satisfies:
abcd... = a^n + b^n + c^n + d^n + ...
Example:
Because it teaches you:
It’s an ideal beginner problem that requires critical thinking and structured logic.
Copy Code
#include <stdio.h>
#include <math.h>
int main() {
int num, originalNum, remainder, result = 0;
printf("Enter a 3-digit number: ");
scanf("%d", &num);
originalNum = num;
while (originalNum != 0) {
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}
if (result == num)
printf("%d is an Armstrong number.\n", num);
else
printf("%d is not an Armstrong number.\n", num);
return 0;
}Sample Output:
Enter a 3-digit number: 371
371 is an Armstrong number.
Let’s break it down:
Copy Code
#include <stdio.h>
#include <math.h>
int main() {
int num, originalNum, remainder, result = 0, n = 0;
printf("Enter an integer: ");
scanf("%d", &num);
originalNum = num;
while (originalNum != 0) {
originalNum /= 10;
++n;
}
originalNum = num;
while (originalNum != 0) {
remainder = originalNum % 10;
result += pow(remainder, n);
originalNum /= 10;
}
if (result == num)
printf("%d is an Armstrong number.\n", num);
else
printf("%d is not an Armstrong number.\n", num);
return 0;
}Think of Armstrong numbers like a password that only opens a digital lock if the digits cooperate perfectly using a math trick. If even one digit misbehaves, the lock won’t open. It’s that precision that makes this number special.
Q1. Can Armstrong numbers have more than 3 digits?
Yes! Numbers like 9474 and 54748 are valid Armstrong numbers.
Q2. How do you calculate the power in C?
Use the pow() function from <math.h>
Q3. What if I use ^ instead of pow()?
That would be wrong. In C, ^ is the bitwise XOR operator, not exponentiation.
Q4. What type should I use for large Armstrong numbers?
Use long long int or unsigned long for larger numbers.
Q5. Can we write this program without using math.h?
Yes, by multiplying the number manually (e.g., remainder * remainder * remainder)
Armstrong numbers might seem like a mathematical riddle, but once decoded with C, they become an excellent exercise in logic building and number manipulation. From working with loops to practicing mathematical operations, this program has it all.
Want to build more programs like this from scratch?
Follow Uncodemy’s C Programming Tutorials and take your coding to the next level!
Meta Title:
What Is an Armstrong Number? Definition, Examples & C Program
Meta Description:
Understand what an Armstrong number is, its definition, and how to implement it in C programming. Includes detailed examples, C code, output, and explanation with Uncodemy's learning re
Personalized learning paths with interactive materials and progress tracking for optimal learning experience.
Explore LMSCreate professional, ATS-optimized resumes tailored for tech roles with intelligent suggestions.
Build ResumeDetailed analysis of how your resume performs in Applicant Tracking Systems with actionable insights.
Check ResumeAI analyzes your code for efficiency, best practices, and bugs with instant feedback.
Try Code ReviewPractice coding in 20+ languages with our cloud-based compiler that works on any device.
Start Coding
TRENDING
BESTSELLER
BESTSELLER
TRENDING
HOT
BESTSELLER
HOT
BESTSELLER
BESTSELLER
HOT
POPULAR