# 24+ CPP Armstrong Checker & Finder Examples

This post contains a total of 24+ Hand-Picked CPP Armstrong Number Checker & Finder Program Examples with Source Code. All the Armstrong Number Checker & Finder programs are made using C++ Programming Language.

You can use the source code of these programs for educational purpose with credits to the original owner.

### Related Posts

Click a Code to Copy it.

## 1. By Frost

Made by Frost. Simple C++ Armstrong number checker to check whether a three digit number is Armstrong or not. ( Source )

```Enter a no:153
Armstrong no!```
``````#include <iostream>
using namespace std;

//Armstrong number for 3 digits

int main()
{
int n,digit,temp,sum=0;

cout<<"Enter a no:\n";
cin>>n;
temp=n;

while(n!=0)
{
digit=n%10;
sum=sum+(digit*digit*digit);
n=n/10;
}

if(temp==sum)
cout<<"Armstrong no!";
else
cout<<"Not an Armstrong no!";

return 0;
}``````

## 2. By [email protected]

Made by [email protected] C++ program to check if a number is Armstrong or not, there is no limit. ( Source )

```_____TO FIND NO. IS ARMSTRONG OR NOT____

Enter any integer number :123
The given number is not Armstrong```
``````#include <iostream>
using namespace std;

int main() {

int num,temp=0,new1=0,rem=0;

cout<<"_____TO FIND NO. IS ARMSTRONG OR NOT____";
cout<<"\n \n An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.\n\nexample, 371 is an Armstrong number since 3*3*3 + 7*7*7 + 1*1*1 = 371. ";

cout<<"\n\n\n Enter any integer number :";
cin>>num;
cout<<num;

temp=num;

while(temp>0)
{
rem=temp%10;
new1+=rem*rem*rem;
temp=temp/10;

}

if(new1==num)
{
cout<<"\n The given number is Armstrong";
}

else
{
cout<<"\n The given number is not Armstrong";
}
return 0;
}``````

## 3. By saurabh

Made by saurabh. Enter 3 digit number. ( Source )

```153
153 is an Armstrong number.```
``````
/*A positive integer is called an Armstrong number (of order n) if

abcd... = an + bn + cn + dn + ...
In the case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example, 153 is an Armstrong number because

153 = 1*1*1 + 5*5*5 + 3*3*3
*/
#include <iostream>
using namespace std;

int main() {
int num, originalNum, remainder, result = 0;
cin >> num;
originalNum = num;

while (originalNum != 0) {
// remainder contains the last digit
remainder = originalNum % 10;

result += remainder * remainder * remainder;

// removing last digit from the orignal number
originalNum /= 10;
}

if (result == num)
cout << num << " is an Armstrong number.";
else
cout << num << " is not an Armstrong number.";

return 0;
}``````

## 4. By Sheena Singh

Made by Sheena Singh. This is the Armstrong number program, which checks if a number entered by the user is an Armstrong number or not. ( Source )

```171
171 is not an Armstrong number!```
``````
//Example: 153 = 1^3 + 3^3 + 5^3 = 1 + 27 + 125 = 153   (here n=3)
#include <iostream>
#include <cmath>
using namespace std;

int no_of_digits(int n)
{
int no=0;
while(n>0)
{
no++;
n/=10;
}
return no;
}

int main()
{
int num,sum=0,temp,num_dig;
float s,sample;
cin>>num;
temp=num;
num_dig=no_of_digits(num);
while(temp>0)
{
s=temp%10;
sample=pow(s,num_dig);
sum+=sample;
temp/=10;
}
if(sum==num)
cout<<num<<" is an Armstrong number!";
else
cout<<num<<" is not an Armstrong number!";
return 0;
}

``````

## 5. By Swati Tiwari

Made by Swati Tiwari. ( Source )

```371
it is a Armstrong number ```
``````/*
371=3^3 +7^3 +1^3
*/

#include <iostream>
using namespace std;

int main() {
int num, i=0,r,sum=0,s;
//cout <<"enter a number to check it is Armstrong no. or not ";
cin>>num;
s=num;
while (i<num)
{
r=num%10;
sum =sum+(r*r*r);
num =num/10;
}

if(sum==s)
cout <<"it is a Armstrong number ";
else
cout <<"it is not a Armstrong number ";
return 0;
}``````

## 6. By ROHIT KANOJIYA

Made by ROHIT KANOJIYA. ( Source )

```123
123 is Not Armstrong Number.```
``````#include <iostream>
#include<cmath>
using namespace std;
/*
An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.

For example, 153 is an Armstrong number,
as 1^3 + 5^3 + 3^3 = 153
Armstrong Numbers : 1,153,370,371,407,8208,9474
*/
int Armstrongcheck(int);
int main()
{
int num;
// cout<<"Enter a Number:";
cin>>num;
// for(num=1;num<=1000;num++)
if(Armstrongcheck(num) == 1)
cout<<num<<" is Armstrong Number."<<endl;
else
cout<<num<<" is Not Armstrong Number."<<endl;
return 0;
}
int Armstrongcheck(int num)
{
int n,sum,rem,digit=0;
float p;
n=num;
while(n!=0)
{
digit++;
n=n/10;
}
n=num;
sum=0;
while(n!=0)
{
rem=n%10;
p=pow(rem,digit);
sum+=p;
n=n/10;
}
if(sum==num)
return 1;
else
return 0;
}``````

## 7. By Ankith R V

Made by Ankith R V. ( Source )

```Enter the number

273
The number is not an Armstrong number```
``````

#include <iostream>
using namespace std;

int main() {
int a,n,m,b=0;
cout<<"Enter the number \n";
cin>>n;
m=n;
while(n!=0)
{
a=n%10;
b+= a*a*a;
n=n/10;
}
if(m==b){
cout<<"The no is an armstrong number"<<endl;
}
else
{
cout<<"The number is not an armstrong number"<<endl;
}
return 0;
}``````

Made by Mohammad Dakdouk. C++ Program to check whether a given number is an Armstrong number or not. ( Source )

```15332
15332 is not Armstrong

=======================
Regards,
``````#include <iostream>
#include <math.h>
using namespace std;

int Armstrong(int n){
int i;
int temp = n;
int rem;
int digit = 1;
int sum = 0;

if( n < 100 || n > 999){
return 0;
}

while(n){
rem = n % 10;
n = n/10;

for(i = 0; i < 3; i++){
digit *= rem;
}

sum += digit;
digit = 1;
}

if(sum != temp){
return 0;
}

return 1;
}

int main() {

int num;

cin >> num;

if(Armstrong(num)){
cout << num << " is Armstrong";
}else{
cout << num << " is not Armstrong";
}

cout << "\n\n";
cout << "Thanks for your ";
cout << "caring...\n\n          ";
cout << "=======================";

return 0;
}``````

## 9. By XXX

Made by XXX. This program will print out all the valid Armstrong numbers from 0 to 100000. You can change the limit by changing the value at define LIMIT 100000. ( Source )

```Armstrong numbers between 0 and 100000:
0 1 2 3 4 5 6 7 8 9 153 370 371 407 1634 8208 9474 54748 92727 93084 ```
``````
#include <iostream>
#define LIMIT 100000
using namespace std;

bool is_armstrong_asm(unsigned int num){
bool a;
asm volatile (R"(
.intel_syntax noprefix

jmp _start
_pow:
push rcx
cmp rbx, 0
je _pow_zero
mov rcx, rax
mov rax, 1

_pow_loop:
dec rbx
mul rcx
cmp rbx, 0
jne _pow_loop
pop rcx
ret

_pow_zero:
mov rax, 1
pop rcx
ret

_num_len:
push rcx
mov rcx, 0
_num_len_loop:
mov rdx, 0
mov rdi, 10
div rdi

inc rcx
cmp rax, 0
jne _num_len_loop
mov rax, rcx
pop rcx
ret

_armstrong:
push rax
call _num_len
mov rsi, rax
pop rax

push rbx
push rax
mov rbx, 0
mov rdi, 10

_armstrong_loop:
mov rdx, 0
div rdi
push rax
push rbx
mov rax, rdx
mov rbx, rsi
call _pow
pop rbx
pop rax

cmp rax, 0
jne _armstrong_loop

pop rax
mov rdx, rbx
pop rbx
cmp rax, rdx
je _is_armstrong
jmp _not_armstrong

_is_armstrong:
mov rax, 1
ret
_not_armstrong:
mov rax, 0
ret

_start:
call _armstrong

.att_syntax noprefix
)"
: "=a" (a)
: "a" (num)
);
// std::cout << "";
return a;
}

int main() {
std::cout << "Armstrong numbers between 0 and " << LIMIT << ":" << std::endl;
for (int i = 0; i < LIMIT; i++) {
if (is_armstrong_asm(i))
cout << i << " ";
}
return 0;
}
``````

## 10. By Jojo Apocalypse

Made by Jojo Apocalypse. C++ program to find the Armstrong numbers between the input range. Enter the start number for first input then enter the limit number for second number, Both numbers must be positive. The program is a little bit buggy. ( Source )

```start :1
end :1000
The Armstrong number(s) are:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407```
``````#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <vector>

using namespace std;

bool isArmstrong(int ex) //153
{
string exStr = to_string(ex);//"153"
int len = exStr.length(), accum=0,curdi; //len:3

for (int i=0;i<len;i++)//i<3
{
char p = exStr[i];
stringstream ss;
ss << p;
ss >> curdi;
accum += pow(curdi,len);
}
if (accum==ex) {return true;}
else {return false;}
}

int main(void)
{
unsigned int min, max;
vector <int> nums;
int lstlen;
//input
cout<<"start :";
cin>>min;
cout << endl;
cout<<"end :";
cin>>max;
cout << endl;

for (int i=min;i<max;i++) //good
{
bool a = isArmstrong(i);
if (a==true){nums.push_back(i);}
}
lstlen = nums.size();
cout << "\n\nThe Armstrong number(s) are:\n";
if (nums.size()>0){
for (int k=0;k<lstlen;k++)
{
cout << nums[k];
if (k==--lstlen)
{
cout << endl;
}else{
cout << ", ";
}
}
}else{
cout << "none.\n";
}
}``````

Made by Ivan Vladimirov. Program checks whether a given number is an Armstrong or not and also prints all the Armstrong numbers that exist in your input range. ( Source )

```Write an integer.

Number 145 is not an Armstrong number:
1^3 + 4^3 + 5^3 = 190

All Armstrong numbers from 0 to 145:
0 1 2 3 4 5 6 7 8
9 ```
``````//number: 1^3+5^3+3^3=153.

#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

void armstrong(int a, vector<int>& arm_num)
{
vector<int> digits;
for (int b = 0; b <= a; b++)
{
digits.clear();
int n = b;
while (n)
{
digits.push_back(n % 10);
n = (n - (n % 10)) / 10;
}
n = digits.size();
int sum = 0;
for (int i = 0; i < n; i++)
sum += pow(digits[i], n);
if (b == sum)
arm_num.push_back(b);
}
}

int main()
{
cout << "Write an integer.\n";
int a;
cin >> a;
a = (a < 0 ? -a : a);
cout << "\nYour number is " << a << ".\n";
vector<int> digits;
int n = a;
while (n)
{
digits.push_back(n % 10);
n = (n - (n % 10)) / 10;
}
n = digits.size();
int sum = 0;
for (int i = 0; i < n; i++)
sum += pow(digits[i], n);
if (a == sum)
cout << "Number " << a << " is an Armstrong number:\n";
else
cout << "Number " << a << " is not an Armstrong number:\n";
for (int i = n - 1; i >= 0; i--)
{
cout << digits[i] << "^" << n;
if (i != 0)
cout << " + ";
else
cout << " = " << sum;
}
cout << "\n\nAll Armstrong numbers from 0 to " << a << ":\n";
vector<int> arm_num;
armstrong(a, arm_num);
n = 0;
for (int i = 0; i < arm_num.size(); i++)
{
cout << arm_num[i] << " ";
n++;
if (n == 9)
{
n = 0;
cout << endl;
}
}
cout << endl;
system("pause");
return 0;
}``````

## 12. By Chris

Made by Chris. This C++ program will print all the Armstrong numbers between a given input range. ( Source )

```Armstrong numbers in the range from 0 to 9999:

0
1
2
3
4
5
6
7
8
9
153
370
371
407
1634
8208
9474```
``````#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

/*
* UPDATE: For a more beautiful output I decided to include <iomanip> and <vector>.
* Instead of directly printing the numbers in the main function, I save them and print them later.
*/

bool armstrong(int input)
{
int n = input;  // the nth digit
int result = 0; // we'll calculate the powers of the digits and add them up
int r;          // the remainder from the modulo operation <=> the value of the current digit
int power = 0, summand; // for the power function

// Count the digits to find the power.
for (int i = input; i != 0; i /= 10)
++power;

while (n != 0)
{
// Find the next digit.
r = n % 10;

// The pow()-function from the cmath library will calculate wrong results for integers.
// Instead of using doubles I'll save memory and implement my own power function here.
summand = r;
for (int i = 1; i < power; ++i)
summand *= r;

// Add the n-th power of the given digit to the result.
result += summand;
n /= 10;
}

// Et voila.
return (input == result) ? true : false;
}

int main()
{
// Getting input
int range;
cin >> range;

// Finding the numbers
vector<int> numbers;
for (int i = 0; i <= range; ++i)
if (armstrong(i))
numbers.push_back(i);

// Formatting stuff
int width = 0;
for (int i = numbers.back(); i != 0; i /= 10)
++width;

// Ouput
cout << "Armstrong numbers in the range from 0 to " << range << ":\n\n";
for (int n : numbers)
cout << setw(width) << n << endl;

return 0;
}``````

## 13. By Tapabrata Banerjee

Made by Tapabrata Banerjee. Simple program to check if a number is Armstrong or not. ( Source )

```Enter number: 123
Number is Not Armstrong Number```
``````#include <iostream>
using namespace std;

int main()
{
int s = 0, n, d;
cout<<"Enter number: \n";
cin>>n;
int x = n;
while (x!=0)
{
d = x%10;
s+=(d*d*d);
x/=10;
}
if (s==n)
{
cout<<"Number is Armstrong Number";
}
else
{
cout<<"Number is Not Armstrong Number";
}
return 0;
}``````

## 14. By deeyae

Made by deeyae. ( Source )

```371
371 is a Armstrong number```
``````#include<iostream>
#include<math.h>
using namespace std;
int main(){
int a,temp,dis,d,digit,temp2;
dis=digit=0;
cin>>a;
temp2=temp=a;
while(a!=0){
a/=10;
digit++;
}
while(temp!=0){
d=temp%10;
//         cout<<"d= "<<d<<'\n';
dis+=pow(d,digit);
//         cout<<"dis= "<<dis<<'\n';
temp/=10;
//         cout<<"temp= "<<temp<<'\n';
}
if(dis==temp2){
cout<<endl<<temp2<<" is a Armstrong number";
}else{
cout<<endl<<temp2<<" is not a Armstrong number";
}
return 0;
}``````

## 15. By Shruti

Made by Shruti. ( Source )

```Enter the number: 121
Number is not Armstrong```
``````#include <iostream>
using namespace std;

int main() {
int n,temp,r=0,a=0;
cout<<"Enter the number:"<<endl;
cin>>n;
temp=n;
while(temp>0)
{
r=temp%10;
a=a+(r*r*r);
temp=temp/10;
}
if(a==n)
cout<<"Number is Armstrong";
else
cout<<"Number is not Armstrong";
return 0;
}``````

## 16. By Shreya

Made by Shreya. Simple Armstrong number checker. ( Source )

```370
370 is an Armstrong number.```
``````#include <iostream>
#include<math.h>
using namespace std;

int main() {
int num,sum=0,nu,rem;
cin>>num;//Enter a number...
nu=num;
while(nu>0)
{
rem=nu%10;
sum+=pow(rem,3);
nu/=10;
}
if(sum==num)
cout<<num<<" is an Armstrong number.";
else
cout<<num<<" is not an Armstrong number.";
return 0;

}``````

## 17. By Morpheus

Made by Morpheus. Input : give a positive no to check for Armstrong. ( Source )

```124
124 is not a armstrong no```
``````#include <iostream>
using namespace std;

int main() {
int arm, num, digit, sum=0;
cin>>arm;

num=arm;

while(num!=0)
{
digit=num%10;
sum+=digit*digit*digit;
num/=10;
}

if(sum==arm)
cout<<arm<<" is armstrong no.\n";
else
cout<<arm<<" is not a armstrong no\n";
return 0;
}``````

## 18. By Saroj Patel

Made by Saroj Patel. ( Source )

```You Entered : 431
431 is not a armstrong number.```
``````#include<iostream>
using namespace std;
#include<math.h>
int main(){
int num,temp,sum=0,mod,i=0;
cin>>num;
cout<<"You Entered : "<<num<<endl;
temp=num;
while(temp>0){
temp/=10;
++i;
}//This loop is used to find the number of digit
temp=num;
while(temp>0){
mod=temp%10;
float p=pow(mod,i);
sum+=p;
temp/=10;
}
if(sum==num)
cout<<num<<" is armstrong number.\n"<<endl;
else
cout<<num<<" is not a armstrong number.\n"<<endl;
return(0);

}
``````

## 19. By salman

Made by salman. Simple program to get the Armstrong numbers between a given range. ( Source )

```Enter the limit : 7777
The Armstrong numbers below 7777 are :-
0
1
153
370
371
407```
``````#include <iostream>
#include <cmath>
using namespace std;

int isArm(int n)
{
int b, num, arm = 0;
num = n;
while (n > 0)
{
b = n % 10;
arm = arm + pow(b, 3);
n = n / 10;
}
return (num == arm);
}

void limit(int limit)
{
for (int a = 0; a <= limit; a++)
if (isArm(a))
cout<<a<<"\n";
}

int main ()
{
int input/*i, length = 0*/;
cout<<"Enter the limit : ";
cin>>input; 	/*for (i = input; i > 0; i /= 10) 		length++;*/
cout<<"\nThe Armstrong numbers below "<<input<<" are :- \n";
limit(input);
return 0;
}
``````

## 20. By J.G.

Made by J.G. The program prints the Armstrong numbers that are below 1000. You can change the range by changing the line ‘ for(int i = 1; i < 1000; i++){ ‘. ( Source )

```1 is an armstrong number.
64 is an armstrong number.
125 is an armstrong number.
216 is an armstrong number.
729 is an armstrong number.```
``````#include <iostream>
#include <math.h>

using namespace std;

int main() {
for(int i = 1; i < 1000; i++){
int sor = i, sum = 0;
while(sor>0){
sor %= 10;
sum += sor*sor*sor;
sor /= 10;
}
if(sum == i){cout<<i<<" is an armstrong number."<<endl;}
}
return 0;
}``````

## 21. By NEEL SHAH

Made by NEEL SHAH. This C++ program prints out the Armstrong numbers that are in a given range. ( Source )

```Enter 1 Number: 1
Enter 2 Number: 1000
i = 1
i = 153
i = 370
i = 371
i = 407```
``````#include <iostream>
using namespace std;
/* ARMSTRONG means

1 cube+5cube+3cube=153

EXAMPLE: 1 ,153, 370,371,407 */

int main() {

int n1,n2,sum,l_digit,i;

cout<<endl<<"Enter 1 Number:";

/* ENTER RANGE 1 TO 1000*/

cin>>n1;

cout<<endl<<"Enter 2 Number:";

cin>>n2;

for(i=n1;i<=n2;i++)
{
sum=0;

for(n1=i;n1>0;n1/=10)
{

l_digit=n1%10;
sum=sum+l_digit*l_digit*l_digit;

}
if(sum==i)

cout<<endl<<"i = "<<i;
}

return 0;
}``````

## 22. By Shobhit

Made by Shobhit. ( Source )

```Enter a number
407
The number is an armstrong number```
``````#include <iostream>
#include <math.h>
using namespace std;

int main() {
int n,p,rem,sum=0;
cout<<"Enter a number\n";
cin>>n;
p=n;
while(n){
rem=n%10;
sum+=pow(rem,3);
n/=10;
}if(sum==p)
cout<<"The number is an armstrong number";
else
cout<<"The number is not an armstrong number";

return 0;
}``````

## 23. By Hrutik Bhalerao

Made by Hrutik Bhalerao. Program to find Armstrong numbers between 1 to 500. ( Source )

```Armstrong numbers in between 1 to 500 are :
1
153
370
371
407```
``````
#include <iostream>
using namespace std;
class armstrong {
private :
int sum,i,t,a;
public :
armstrong ();
};
armstrong::armstrong () {
cout<<endl<<"Armstrong numbers in between 1 to 500 are :"<<endl;
for(i = 1; i <= 500; i++)
{
t = i;
sum = 0;
while(t != 0) {
a = t%10;
sum += a*a*a;
t = t/10;
}
if(sum == i)
cout<<i<<endl;  }
}
int main(){
armstrong A;
return 0;
}``````

## 24. By Dmytro Kovryzhenko

Made by Dmytro Kovryzhenko. Armstrong numbers below 1000000. ( Source )

```Next we would like to get all
Armstrong numbers below 1000000.

#1. Armstrong number i=0;
#2. Armstrong number i=1;
#3. Armstrong number i=2;
#4. Armstrong number i=3;
#5. Armstrong number i=4;
#6. Armstrong number i=5;
#7. Armstrong number i=6;
#8. Armstrong number i=7;
#9. Armstrong number i=8;
#10. Armstrong number i=9;
#11. Armstrong number i=153;
#12. Armstrong number i=370;
#13. Armstrong number i=371;
#14. Armstrong number i=407;
#15. Armstrong number i=1634;
#16. Armstrong number i=8208;
#17. Armstrong number i=9474;
#18. Armstrong number i=54748;
#19. Armstrong number i=92727;
#20. Armstrong number i=93084;
#21. Armstrong number i=548834;

Thank you for attention!```
``````#include <iostream>
using namespace std;

//Function which give you sum of cubes for each digit in
//the input number
int get_sum_cub(long long k, long long &sum)
{
int z=0, i; long long c=k, y;
while (c)
{
z++;
c/=10;
}
while (k)
{
y=1;
for (i=1;i<=z;i++) y *= (k%10);
sum += y;
k/=10;
i=1;
}
}

int main()
{
//Declaration and initialization of main parameters
long long i=0, sum=0; int k=0;
//Range of Armstrong number research
long long N=1000000;

cout<<"Next we would like to get all"<<endl;
cout<<"Armstrong numbers bellow "<<N<<"."<<endl;
cout<<endl;

for (i=0;i<N;i++)
{
sum=0;
get_sum_cub(i, sum);
//Only Armstrong numbers will be print
if(sum==i)
cout<<"#"<<++k<<". Armstrong number i="<<i<<";"<<endl;
}

cout<<endl;
cout<<"Thank you for attention!"<<endl;
}``````

## 25. By Ashish Goyal

Made by Ashish Goyal. ( Source )

```2424
non - armstrong number```
``````#include <iostream>
using namespace std;

int main() {

int n;
cin>>n;

int sum=0;
int orgnln = n;

while(n>0){
int lastdigit;
lastdigit = n%10;

int a;
a= lastdigit*lastdigit*lastdigit;

sum += a;

n=n/10;
}

if(sum==orgnln){
cout<<"armstrong number";
}
else{
cout<<"non - armstrong number";
}

return 0;
}``````