Check Armstrong Number
C++
Hard
3 views
Problem Description
Number equals sum of cubes of its digits. Example: 153 = 1³+5³+3³
Real Life: Special numbers in mathematics.
Step-by-Step Logic:
1. Take original number and save it
2. Extract each digit one by one
3. Calculate cube of each digit
4. Add all cubes
5. If sum equals original, it's Armstrong
Official Solution
void control_q12_armstrong() {
int number = 153;
int original = number;
int sum = 0;
while(number > 0) {
int digit = number % 10; // Get last digit
sum = sum + (digit * digit * digit); // Add cube
number = number / 10; // Remove last digit
}
if(sum == original) {
cout << original << " is an Armstrong number" << endl;
} else {
cout << original << " is NOT an Armstrong number" << endl;
}
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!