From ca7bef395a04a0620af57a9c63bcda197d20ad32 Mon Sep 17 00:00:00 2001 From: Md Ansar Hussain <91614411+MdAnsar7@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:11:46 +0530 Subject: [PATCH] Create Armstrong.cpp --- Add Code Here/Armstrong.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Add Code Here/Armstrong.cpp diff --git a/Add Code Here/Armstrong.cpp b/Add Code Here/Armstrong.cpp new file mode 100644 index 00000000000..512806e7684 --- /dev/null +++ b/Add Code Here/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; +}