0
1.4kviews
What do you mean by Recursion? Write a program which will add first n natural numbers using Recursion.
1 Answer
1
68views

In programming, when a function calls itself the case is called recursion and the function involved is called recursive function.

#include<stdio.h>
int add(int n);
void main()
{
int n;
    printf("Enter a positive integer: ");
    scanf("%d",&n);
    printf("Sum = %d",add(n));
getche();
}
int add(int n)
{
if(n!=0)
return n+add(n-1);/* recursive call */
    else
     return 0;
}

Output

Enter a positive integer: 5Sum = 15

Please log in to add an answer.