C Programming Code Examples C > Functions Code Examples C program to find sum of natural numbers in given range using recursion C program to find sum of natural numbers in given range using recursion Write a recursive function in C programming to find sum of all natural numbers between 1 to n. How to find sum of all natural numbers using recursion in C program. First give a meaningful name to the function, say sumOfNaturalNumbers(). Next the function must accept two inputs i.e. the lower and upper limit to find sum. Hence, pass two integer parameters to the function say sumOfNaturalNumbers(int start, int end). Finally, the function must return sum of natural numbers between start and end. Therefore return type of function should be int. The final function declaration to find sum of all natural numbers in given range is - int sumOfNaturalNumbers(int start, int end); #include <stdio.h> /* Function declaration */ int sumOfNaturalNumbers(int start, int end); int main() { int start, end, sum; /* Input lower and upper limit from user */ printf("Enter lower limit: "); scanf("%d", &start); printf("Enter upper limit: "); scanf("%d", &end); sum = sumOfNaturalNumbers(start, end); printf("Sum of natural numbers from %d to %d = %d", start, end, sum); return 0; } /* Recursively find the sum of natural number */ int sumOfNaturalNumbers(int start, int end) { if(start == end) return start; else return start + sumOfNaturalNumbers(start + 1, end); }