23. write a C program to find the factorial of a number using recursive functions


Program to find the factorial of a number using recursive functions 

Source Code:

#include<stdio.h>
int fact(int n)
{
int f;
if(n==0)
return 1;
else
f=n*fact(n-1);
return f;
}
int main()
{
int i,j;
printf(" Enter I Value:\n");
scanf("%d",&i);
j=fact(i);
printf("Factorial of %d is =%d",i,j);
}

Output:

Enter I Value:
7
Factorial of 7 is =5040

No comments:

Post a Comment