Recursion is the process which repeat itself until some condition is reached otherwise it gets repeated again and again.
In programming languages, if a program allows to call a function inside the same function, then it is called a recursive call of the function.
void recursion() {
recursion(); /* function calls itself */
}
int main() {
recursion();
}
Recursion is used in the programming where repetition needs to be done for the same process but for the different values .
Recursion also increase the programming load of the CPU in terms of execution so its better to avoid recursion for large program manipulation.
#include <stdio.h>
int factorial(unsigned int i) {
if(i <= 1) {
return 1;
}
return i * factorial(i - 1);
}
int main() {
int i = 15;
printf("Factorial of %d is %d\n", i, factorial(i));
return 0;
}
0 Comment(s)