C Programming Code Examples C > Functions Code Examples print all Armstrong numbers between given interval using function print all Armstrong numbers between given interval using function Write a function to print all Armstrong numbers between given interval in C programming. How to print all Armstrong numbers in given range using functions in C programming. Declare function to print Armstrong numbers in given range First give a meaningful name to function. Say printArmstrong() function prints all Armstrong numbers in given range. Next the function prints Armstrong number in given range. Hence, we must pass two integer parameters to the function, say printArmstrong(int start, int end);. Finally the function prints all Armstrong numbers in given range returning nothing. Therefore, return type of the function must be void. The final function declaration to print all Armstrong numbers in given range is - void printArmstrong(int start, int end);. #include <stdio.h> /* Function declarations */ int isArmstrong(int x); void printArmstrong(int start, int end); int main() { int start, end; /* Input lower and upper limit to of armstrong numbers */ printf("Enter lower limit to print armstrong numbers: "); scanf("%d", &start); printf("Enter upper limit to print armstrong numbers: "); scanf("%d", &end); printf("All armstrong numbers between %d to %d are: \n", start, end); printArmstrong(start, end); return 0; } /** * Check whether the given number is armstrong number or not. * Returns 1 if the number is armstrong otherwise 0. */ int isArmstrong(int x) { int temp, lastDigit, sum; temp = x; sum = 0; /* Calculate sum of cube of digits */ while(temp != 0) { lastDigit = temp % 10; sum += lastDigit * lastDigit * lastDigit; temp /= 10; } /* * Check if sum of cube of digits equals * to original number. */ if(x == sum) return 1; else return 0; } /* Print all armstrong numbers between start and end. */ void printArmstrong(int start, int end) { /* * Iterates from start to end and print the current number * if it is armstrong */ while(start <= end) { if(isArmstrong(start)) { printf("%d, ", start); } start++; } }