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



"Please Do Like Facebook Page and follow us on Twitter so that you can actively participate and develop skills in programming. If you find above post interesting do share the webpage."
This entry was posted in c program and tagged , , . Bookmark the permalink.

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>