Recursion is a process in which a function calls itself. In a programming language, if a program allows calling of a function inside the same function, then the function is termed as recursive function and this process of calling itself is called Recursion.
There are two main requirements for a function to be recursive:
1. Terminating condition - the function must return when the terminating condition is satisfied.
2. Recursive call - the function must call itself.
Example:-
int fun()
{
...
...
fun();
...
...
}
Here we can see that, the function fun( ) calls itself.
C program:-
#include <stdio.h>
int fun(int
n)
{
if (n == 0)
return 0;
else
return fun(n - 1) + n;
}
int main()
{
int sum = 0, x;
printf("number");
scanf("%d", &x);
sum = fun(x);
printf("%d\n", sum);
return 0;
}
Well done
ReplyDeleteThanks for the feedback!
DeleteWell explained... ππ
ReplyDeleteThanks for the feedback!
DeleteGood explanation ππ
ReplyDeleteThanks for the feedback!
DeleteGood job πππ
ReplyDeleteThanks for the feedback!
DeleteGood job πππ
ReplyDeleteWell explained
ReplyDeleteThanks for the feedback!
DeleteIt is what I was searching for is really informative. It is a significant and useful article for us. Thankful to you for sharing an article like this. it company in indore
ReplyDelete