codescracker


c++

C++ Program to Check Number is Armstrong or Not



« Previous Program Next Program »


Check Armstrong or Not in C++

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:

After checking for the Armstrong number, print the result on the output screen as shown here in the following program.

C++ Programming Code to Check Armstrong or Not

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:

/* C++ Program - Check Armstrong or Not */
		
#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();
}

When the above C++ program is compile and executed, it will produce the following result. Above C++ Programming Example Output (for Armstrong number):

C++ program find Armstrong number

Above C++ Programming Example Output (for not Armstrong number):

C++ program check Armstrong number

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test