Inspect the following program:
#include <stdio.h>
int j;
int fact( int n )
{
int value = 1;
for ( j=1; j<=n; j++ ) value *= j;
return value;
}
int main ( void )
{
for ( j=1; j<7; j++ )
printf("factorial of %d is %d\n", j, fact(j) );
return 0 ;
}
Its output is the following:
factorial of 2 is 1 factorial of 4 is 6 factorial of 6 is 120
Explain this strange result.