C program to find factorial of a number using recursion
>> Wednesday, November 2, 2011
Factorial is mostly used in calculting permutation and combination. Factorial sign is '!' i.e exclamatory mark.
For eg 4! can be calculated as : 4!=4*3*2*1=24. Here the c program to calculate factorial using recursion function.
#include<stdio.h>
#include<conio.h>
int recfact(int);
main( )
{
int a, fact, rec ;
printf ( "\nEnter any number " ) ;
scanf ( "%d", &a ) ;
rec = recfact ( a ) ;
printf ( "Factorial value = %d", fact ) ;
getch();
}
int recfact( int x )
{
int f ;
if ( x == 1 )
return ( 1 ) ;
else
f = x * recfact ( x - 1 ) ;
return ( f ) ;
}
Output :
c program to find factorial using recursion |
0 comments:
Post a Comment