recursion in c

recursion means, calling the same function within the function. this perform a particular task repeatedly calling itself. There should be terminating statement or else it will be an infinite loop. this function makes program easier and customized un a short way. recursions use more memory


long int product(int n);
int main()
int n;
printf("Enter a positive integer: ");
scanf("%d", &n);
printf("Factorial of %d = %ld", n, product(n));
return 0;
long int product(int n)
if (n >= 1)
return (n*product(n-1));// product function calls itself
return 1;


Enter a positive integer: 5
Factorial of 5 = 120