๐
Date: Jan 30, 2026
๐ฅ Topic: Logic Building: Armstrong Number
๐ช What is an Armstrong Number?
An Armstrong number is a number that is equal to the sum of cubes of its digits.
Example: 153
1³ + 5³ + 3³
= 1 + 125 + 27
= 153 (Matched!)
๐งฉ The Algorithm
To code this, I need to extract digits one by one.
- Get last digit using Modulo (
num % 10). - Cube it and add to Sum.
- Remove last digit using Division (
num / 10). - Repeat until num becomes 0.
๐ป Day 30 Code
#include <iostream>
using namespace std;
int main() {
int n, originalNum, remainder, result = 0;
cout << "Enter an integer: ";
cin >> n;
originalNum = n; // Backup the number
while (originalNum != 0) {
// remainder is the last digit
remainder = originalNum % 10;
// Add cube to result
result += remainder * remainder * remainder;
// Remove last digit
originalNum /= 10;
}
if (result == n)
cout << n << " is an Armstrong number.";
else
cout << n << " is NOT an Armstrong number.";
return 0;
}
๐ Month 1 Complete!
It's been 30 days of consistent coding. From "Hello World" to solving mathematical problems, the journey has been insane.
⏭️ Next Chapter: Bit Manipulation
Next month, I'm diving into the binary magic of Bit Manipulation (XOR, AND, OR tricks) which is a superpower in competitive programming.
Stay Tuned!
No comments:
Post a Comment