programming-examples/c/Functions/C Program to Write a recursive function to find factorial of a given number n..c

31 lines
460 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
/* Factorial - Write a recursive function to find factorial of a given number n */
#include <stdio.h>
#include <conio.h>
long fact(int n)
{
if(n==0)
return 1 ;
else
return ( n * fact(n-1) ) ;
}
void main()
{
int n ;
clrscr() ;
printf("Enter n:") ;
scanf("%d", &n) ;
printf("Factorial of %d is %ld", n, fact(n) ) ;
getch() ;
}
/*
Output:
Enter n:4
Factorial of 4 is 24
*/