Write a C program to find factorial of a given number using recursion function.

8 b]Write a C program to find factorial of a given number using recursion function.

➢ Recursion is the repetitive process in which a function calls itself.
➢ All recursive functions have two elements each call either solves one part of the problem or it reduces the size of the problem.

#include<stdio.h> int fact(int);
void main( )
{
 int n,res;
 printf(“enter the number to find its factorial\n”); scanf(“%d”,&n);
 res=fact(n);
 printf(“factorial of %d=%d”,n,res); getch();
}
 int fact(int n)
{
 if(n==0) return 1;
 else
 return (n*fact(n-1));
}

Leave a Reply

Your email address will not be published. Required fields are marked *