Thursday 21 February 2013

C++ program to find Armstrong number

| |

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. For example, 371 is an Armstrong number since 3^3 + 7^3 + 1^3 = 371.




PROGRAM-
#include <iostream>
using namespace std;
int main()
{
int s, n, m, r;
cout <<"Enter the number \n";
cin >>n;
cout <<" Entered number is \n"<< n;
s=0;
m=n;
do
{
r=n%10;
n=n/10;
s=s+r*r*r;
}while (n!=0);
if(s==m)
cout <<"\nThis is Armstrong number\n";
else
cout <<"\nThis is not Armstrong number\n";
system("pause");
return 0;
}


C++ program to find Armstrong number


Related Posts Plugin for WordPress, Blogger...
Powered by Blogger.