Skip to content

Commit

Permalink
Merge pull request #234 from MdAnsar7/patch-4
Browse files Browse the repository at this point in the history
Create Armstrong.cpp
  • Loading branch information
AkhzarFarhan authored Oct 19, 2024
2 parents 1a9b6f5 + 5e30bb7 commit e0c0045
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions C++/Armstrong.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
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;
}

0 comments on commit e0c0045

Please sign in to comment.