2017-03-30 21:43:26 +08:00
|
|
|
//program to check whether a number is an armstrong number or not
|
2019-08-21 10:10:08 +08:00
|
|
|
#include <iostream.h>
|
|
|
|
#include <Math.h>
|
2017-03-30 21:43:26 +08:00
|
|
|
int main()
|
|
|
|
{
|
2019-08-21 10:10:08 +08:00
|
|
|
int n, k, d, s = 0;
|
|
|
|
cout << "Enter a number:";
|
|
|
|
cin >> n;
|
|
|
|
k = n;
|
|
|
|
while (k != 0)
|
2017-03-30 21:43:26 +08:00
|
|
|
{
|
2019-08-21 10:10:08 +08:00
|
|
|
d = k % 10;
|
|
|
|
s += (int)pow(d, 3);
|
|
|
|
k /= 10;
|
2017-03-30 21:43:26 +08:00
|
|
|
}
|
2019-08-21 10:10:08 +08:00
|
|
|
if (s == n)
|
|
|
|
cout << n << "is an armstrong number";
|
2017-03-30 21:43:26 +08:00
|
|
|
else
|
2019-08-21 10:10:08 +08:00
|
|
|
cout << n << "is not an armstrong number";
|
2017-03-30 21:43:26 +08:00
|
|
|
}
|