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
c program to find factorial using recursion

0 comments:

Post a Comment

About This Blog

This blog will contain c programs related to interview preparation, basic programs, operating system, graphics, data structure, algorithms implementation, compiler and porjects. C is one of the most widely used programming languages of all time. This blog is intended for engineer students and for the people who are preparing for their interview in IT sector.

Share and Save