Written by Sai Sandeep Thota on January 31, 2014 in C++ > Programming

C++ Program to check Armstrong Number

GET ALERTS:

Get our Latest updates delivered to your mailbox!

An Armstrong number is a number in which the sum of cubes of individual digits is equal to the Given number. We have already written C and Java program to check armstrong number, now we are writing C++ Program to check Armstrong number.

Here we have declared a class named Armstrong with public variables n, temp, rem, sum and a function named check();. Then we are defining the body of the function check(); and taking the input from the user to check whether the given input number is Armstrong or not.

You may also consider reading:

C++ Program to check Armstrong Number

#include<iostream.h>

class Armstrong {
	public:
	int n, temp, rem, sum;
	void check();
};

void Armstrong::check() {
	cout<<"\nEnter Number: ";
	cin>>n;
	temp=n;
	while(temp!=0)
	{
		rem = temp%10;
		sum = sum+(rem*rem*rem);
		temp = temp/10;
	}
	
	if(sum==n)
	{
		cout<<"Given Number :"<<n<<" is an Armstrong number";
	}
	else
	{
		cout<<"Given Number :"<<n<<" is not an Armstrong number";
	}
}

void main() {
	Armstrong ob;
	ob.check();
}

Download Source Code

Output:
armstrong_cpp

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: