Factorial using recursion in c code

Factorial using recursion in c codeĀ is mostly used in calculating permutation and combination. As we can see how c program for combination and c program for permutation is implemented. Factorial sign is ‘!’ i.e exclamatory mark.
For eg 4! can be calculated as : 4!=4*3*2*1=24.

Factorial using recursion in c code

#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:

Factorial using recursion in c code
Factorial using recursion in c code

Add Comment Register



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>