2019-12-11 20:23:41 +08:00
|
|
|
// Program to check whether a number is an armstrong number or not
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using std::cout;
|
|
|
|
using std::cin;
|
|
|
|
|
|
|
|
int main() {
|
2019-08-21 10:10:08 +08:00
|
|
|
int n, k, d, s = 0;
|
|
|
|
cout << "Enter a number:";
|
|
|
|
cin >> n;
|
|
|
|
k = n;
|
2019-12-11 20:23:41 +08:00
|
|
|
while (k != 0) {
|
2019-08-21 10:10:08 +08:00
|
|
|
d = k % 10;
|
2019-12-11 20:23:41 +08:00
|
|
|
s += d * d * d;
|
2019-08-21 10:10:08 +08:00
|
|
|
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
|
|
|
}
|