C Program to Display Armstrong Numbers Between 1 and 1000 - Loop Through Range
Display Armstrong Numbers from 1 to 1000
#include <stdio.h>
int main() {
int number, originalNumber, remainder, result;
printf("Armstrong numbers between 1 and 1000 are:\n");
for (number = 1; number <= 1000; ++number) {
originalNumber = number;
result = 0;
// Compute the sum of cubes of digits
while (originalNumber != 0) {
remainder = originalNumber % 10;
result += remainder * remainder * remainder;
originalNumber /= 10;
}
// Check if the number is an Armstrong number
if (result == number) {
printf("%d\n", number);
}
}
return 0;
}
Armstrong numbers between 1 and 1000 are:
1
153
370
371
407
This program iterates through the numbers from 1 to 1000, computes the sum of the cubes of the digits for each number, and prints the number if the sum matches the original. Only a few three‑digit numbers satisfy this property (153, 370, 371 and 407).
⬅ Previous TopicC Program - Check Armstrong Number
Next Topic ⮕C Program - Display Armstrong Number Between Two Intervals
Next Topic ⮕C Program - Display Armstrong Number Between Two Intervals
Comments
Loading comments...