Q.
98. Program to accept a number and check if its an Armstrong number
(sum of cubes of each digit = that number. Eg: 153, 371, 407).
Copy Code:
#include <iostream>
using namespace std;
int main()
{
int i, n, s=0, p, a[ 10 ];
cout << " Enter a possible Armstrong Number "; cin >> n; p = n;
for ( i=0 ; n>0 ; ++i )
{
a[ i ] = n % 10;
n = n/10;
s = s + a[ i ] * a[ i ] * a[ i ] ;
}
if (s==p)
cout << p << " is ARMSTRONG ";
else
cout << p << " is NOT ARMSTRONG";
return 0;
}
No comments:
Post a Comment