 # C++ Programming Code Examples

## C++ > Mathematics Code Examples

### Check the Number is Armstrong or Not

``` Check the Number is Armstrong or Not To check whether a number is an Armstrong number or not an Armstrong number in C++ programming, you have to ask to the user to enter the number (any positive number), now check for the Armstrong number i.e., whether the entered/given number is an Armstrong number or not. To check whether any positive number is an Armstrong number or not, following is the example: Since 153 is equal to 1*1*1 + 5*5*5 + 3*3*3. So 153 is an Armstrong number Since 12 is not equal to 1*1*1 + 2*2*2. So 12 is not an Armstrong number Following C++ program ask to the user to enter any positive integer to find whether it is an Armstrong number or not, then display the result on the screen: #include<iostream.h> #include<conio.h> void main() { clrscr(); int n, nu, num=0, rem; cout<<"Enter any positive number : "; cin>>n; nu=n; while(nu!=0) { rem=nu%10; num=num + rem*rem*rem; nu=nu/10; } if(num==n) { cout<<"Armstrong Number"; } else { cout<<"Not Armstrong Number"; } getch(); } ``` 