C Programming Code Examples C > Functions Code Examples print all natural numbers from 1 to n using recursion print all natural numbers from 1 to n using recursion Write a recursive function in C programming to print all natural numbers between 1 to n. How to print all natural numbers from 1 to n using recursion in C program. Declare recursive function to print natural numbers in given range First let us give a meaningful name to our function, say printNaturalNumbers(). Next we need to print natural numbers in range. Hence, the function must accept two parameters i.e. start and end limit to print natural numbers. For that let us update our function declaration say printNaturalNumbers(int lowerLimit, int upperLimit);. Finally the function should print all natural numbers in given range returning nothing i.e. void. Function declaration to print all natural numbers in given range should look like void printNaturalNumbers(int lowerLimit, int upperLimit); Base condition of recursive function to print natural numbers is loweLimit < upperLimit. Which is our required condition to return control from function. After checking base condition print the value of lowerLimit and make a recursive call to printNaturalNumbers() function i.e. printNaturalNumbers(lowerLimit + 1, upperLimit);. #include <stdio.h> /* Function declaration */ void printNaturalNumbers(int lowerLimit, int upperLimit); int main() { int lowerLimit, upperLimit; /* Input lower and upper limit from user */ printf("Enter lower limit: "); scanf("%d", &lowerLimit); printf("Enter upper limit: "); scanf("%d", &upperLimit); printf("All natural numbers from %d to %d are: ", lowerLimit, upperLimit); printNaturalNumbers(lowerLimit, upperLimit); return 0; } /* Recursively prints all natural number between the given range. */ void printNaturalNumbers(int lowerLimit, int upperLimit) { if(lowerLimit > upperLimit) return; printf("%d, ", lowerLimit); // Recursively call the function to print next number printNaturalNumbers(lowerLimit + 1, upperLimit); }