Programming for Problem Solving

GTU Practical 46

46. Write a program to find the factorial of a number using recursion.
#include<stdio.h>  ( this applies in the given code )

#include

int fact(int);

int main()
{
int n;
printf(“\n Enter Value of n :”);
scanf(“%d”,&n);
printf(“Factorial = %d”,fact(n));
return 0;
}

int fact(int n)
{
if(n==1)
{
return 1;
}

return n * fact(n-1);
}

OUTPUT

Enter Value of n :9
Factorial = 362880

GTU STUDY