Armstrong Number Finder
C
Medium
4 views
Problem Description
Print Armstrong numbers from 1 to 1000 (153 = 1³+5³+3³). Nested logic: extract outer loop numbers, inner loop digits and calculate power.
Official Solution
#include <stdio.h>
int main() {
int num, temp, digit;
int sum;
printf("Armstrong numbers from 1 to 1000 are:n");
for (num = 1; num <= 1000; num++) { // Outer loop
temp = num;
sum = 0;
while (temp > 0) { // Inner loop
digit = temp % 10; // Extract digit
sum = sum + (digit * digit * digit);
temp = temp / 10;
}
if (sum == num) {
printf("%d ", num);
}
}
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!