APC-PRAC-037.c (1011B)
1 /* Show all the armstrong number between a range. */ 2 /* Author: Amit Dutta, Date: 21-11-2025 */ 3 4 // This code has not been compiled. 5 // If you find any issues, please create a new issue on GitHub regarding them. 6 // Go to this link to create a new issue: https://github.com/notamitgamer/bsc/issues 7 8 #include <stdio.h> 9 #include <math.h> 10 11 #define lowerBound 100 12 #define upperBound 999 13 14 int isArmstrongNumber(int); 15 16 int isArmstrongNumber(int n) 17 { 18 int temp = n, sum = 0, count = 0; 19 while (temp > 0) 20 { 21 count++; 22 temp /= 10; 23 } 24 temp = n; 25 while (temp > 0) 26 { 27 sum += (int)pow(temp % 10, count); 28 temp /= 10; 29 } 30 return sum == n; 31 } 32 33 int main() 34 { 35 int n, i, count = 0; 36 printf("Armstrong number between %d and %d are: ", lowerBound, upperBound); 37 for (i = lowerBound; i <= upperBound; i++) 38 if (isArmstrongNumber(i)) 39 { 40 printf("%d ", i); 41 count++; 42 } 43 printf("\n\nCount: %d\n", count); 44 return 0; 45 }