top of page
Frequently Asked C Language Interview Question & Answers
What is recursion in C?
Recursion: A function, which calls itself, recursion is simple to write in the program but takes more memory space and time to execute.
Advantages of using recursion:-
-
Avoid unnecessary calling of functions
-
Substitute for iteration
-
Useful when applying the same solution
Factorial program in c using Recursion
#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;
}
bottom of page