diff --git a/C++/Armstrong.cpp b/C++/Armstrong.cpp new file mode 100644 index 000000000..512806e76 --- /dev/null +++ b/C++/Armstrong.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +int main() { + int num, originalNum, remainder, result = 0; + cout << "Enter a three-digit integer: "; + cin >> num; + originalNum = num; + + while (originalNum != 0) { + // remainder contains the last digit + remainder = originalNum % 10; + + result += remainder * remainder * remainder; + + // removing last digit from the original number + originalNum /= 10; + } + + if (result == num) + cout << num << " is an Armstrong number."; + else + cout << num << " is not an Armstrong number."; + + return 0; +}