Home > Programming > Functions using the "C" programming language > example27.c |
/*
In this example we demonstrate a recursive function call.
*/
#include <conio.h>
#include <stdio.h>
/*
Function prototype
*/
long factorial( int );
void main()
{
int i;
for( i=1; i<10; i++ )
printf("Factorial of %d is %ld.\n", i , factorial( i ) );
getch();
}
long factorial( int num )
{
if( (num == 0)||(num==1) )
return 1;
else
return
factorial(num - 1)*num; // <- Recursive call
}
© 2004 Jim Valavanis