C- Program to evaluate the factorial of a number using recursion.

Program to evaluate the factorial of a number using recursion.

#include <stdio.h>

short factorial( short ) ;

void main()

{

short i ;

printf(“Enter an integer and i will try to calculate its factorial : “ ) ;

scanf( “%d”, &i ) ;

printf( “\n\nThe factorial of %d, %d! is %d\n”, i, i, factorial( i ) ) ;

}

short factorial( short num )

{

if ( num <= 1 )

return 1 ;

else

return ( num * factorial( num – 1 ) ) ;

}

error: Content is protected !!