sample
2026 Data Scientist Guide Master Big Data Analytics & Business Intelligence Unlock the power of data visualization, predictive modeling, and statistical analysis. Our comprehensive curriculum

Don’t worry, unlock all articles / blogs on PrepInsta by just simply logging in on our website
On most websites, Armstrong number definition is given wrong. They all assume any number where the sum of the cubes of its digits is equal to the number itself is Armstrong Number.
However, Armstrong number is any number following the given rule –
2026 Data Scientist Guide Master Big Data Analytics & Business Intelligence Unlock the power of data visualization, predictive modeling, and statistical analysis. Our comprehensive curriculum
#include <stdio.h>
#include <math.h>
// Armstrong number is any number following the given rule
// abcd... = a^n + b^n + c^n + d^n + ...
// Where n is the order(length/digits in number)
// Example = 153 (order/length = 3)
// 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
// Example = 1634 (order/length = 4)
// 1634 = 1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634
// number of digits in a number is order
int order(int x)
{
int len = 0;
while (x)
{
len++;
x = x/10;
}
return len;
}
int armstrong(int num, int len){
int sum = 0, temp, digit;
temp = num;
// loop to extract digit, find power & add to sum
while(temp != 0)
{
// extract digit
digit = temp % 10;
// add power to sum
sum = sum + pow(digit,len);
temp /= 10;
};
return num == sum;
}
// Driver Code
int main ()
{
int num, len;
printf("Enter a number: ");
scanf("%d",&num);
// function to get order(length)
len = order(num);
// check if Armstrong
if (armstrong(num, len))
printf("%d is Armstrong", num);
else
printf("%d is Not Armstrong", num);
}
Enter a number: 1634
1634 is Armstrong
Enter a number: 209
209 is Not Armstrong
Enter a number: 153
153 is Armstrong
This method uses recursion in C
#include<stdio.h>
#include <math.h>
int order(int x)
{
int len = 0;
while (x)
{
len++;
x = x/10;
}
return len;
}
int getArmstrongSum(int num, int order){
if(num == 0)
return 0;
int digit = num % 10;
return pow(digit, order) + getArmstrongSum(num/10, order);
}
// Driver Code
int main ()
{
int num, len;
printf("Enter a number: ");
scanf("%d",&num);
// function to get order(length)
len = order(num);
// check if Armstrong
if (num == getArmstrongSum(num, len))
printf("%d is Armstrong", num);
else
printf("%d is Not Armstrong", num);
}Enter a number: 1634 1634 is Armstrong
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
2026 Data Scientist Guide Master Big Data Analytics & Business Intelligence Unlock the power of data visualization, predictive modeling, and statistical analysis. Our comprehensive curriculum
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Get Hiring Updates right in your inbox from PrepInsta