Here you will get program for armstrong number in C++.

A number whose sum of digits raised to power n is equal to itself is called armstrong number. Here n is the total digits in the number.

For example, 153 is armstrong number as 153 = 1^{3 }+ 5^{3 }+ 3^{3} = 1 + 125 +27.

## Program for Armstrong Number in C++

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include<iostream> #include<math.h> using namespace std; int main() { int n,m=0,p=0,x,y; cout<<"Enter any number: "; cin>>n; y=n; while(y!=0){ y=y/10; p++; } y=n; while(n!=0) { x=n%10; m+=pow(x,p); n=n/10; } if(y==m) cout<<"The given number is an armstrong number"; else cout<<"The given number is not an armstrong number"; return 0; } |

**Output**

*Enter any number: 7*

*The given number is an armstrong number*

Thanks man your programs helps me a lot in my homework.

Your welcome bro, keep visiting!! 🙂

there is a fault as wen 1%10, x will become 10 and m will be +1000 rather than +1

The logic is absolutely correct, 1%10 = 1. You are telling wrong logic. Just run the program, it is working fine.

is it also correct for any number more than 3 digits?

Thank you

Good website easy for find out any sol.

neeraj can uhelp me doing vc++ programming

very helpful and resourceful blog

Thanks. It did helped me.