C Program to Add First n Numbers using recursion

C Program to Add First n Numbers using recursion

Write a Program to Add First n Numbers using recursion

// C Program to Add First n Numbers using recursion

#include <stdio.h>

int add(int n)
{
	if(n != 0)
		return n + add(n - 1);
	else
		return n;

}

int main()
{
	int n;

	printf("Enter n :--> ");
	scanf("%d", &n);

	printf("Sum of First %d Numbers : %d", n, add(n));
	return 0;
}

Output:

Enter n :--> 15
Sum of First 15 Numbers : 120