TheAlgorithms-C-Plus-Plus/dynamic_programming/armstrong_number.cpp
2020-05-29 23:26:30 +00:00

24 lines
432 B
C++

// Program to check whether a number is an armstrong number or not
#include <iostream>
using std::cin;
using std::cout;
int main()
{
int n, k, d, s = 0;
cout << "Enter a number:";
cin >> n;
k = n;
while (k != 0)
{
d = k % 10;
s += d * d * d;
k /= 10;
}
if (s == n)
cout << n << "is an armstrong number";
else
cout << n << "is not an armstrong number";
}