C Program to Print Sum of First N Numbers Using Recursion
Recursion in C means a function calling itself. The function dspsum recursively adds the number to the variable sum by decreasing the value of num in every call till it becomes 0.
//C program to print sum of first n numbers using recursion
printf("Enter the Nth number: ");
scanf("%d", &num); //taking input from user
dspsum(num); //calling the recursive function
void dspsum(int num)
static int sum = 0;
if (num == 0)
printf("Sum of first N numbers is %d\n", sum);
sum += num;
Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more.
Sign Up for our weekly newsletter to get update about new content.