#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n = 153; // Change this number to test other values
int num = n;
int cubeSum = 0;
while (num > 0) {
int lastDig = num % 10; // Gets the last digit
cubeSum += lastDig * lastDig * lastDig; // Adds the cube of the digit
num /= 10; // Removes the last digit
}
if (n == cubeSum) {
cout << n << " is an Armstrong number." << endl;
} else {
cout << n << " is not an Armstrong number." << endl;
}
return 0;
}
No comments:
Post a Comment