Hello, i am having a problem with my program. I cant get it to stop and show me the screen.
The program is meant to show the factorial of even numbers 0 one to 40. I would check if it works but i cant see the output screen.
#include <stdio.h>
unsignedlonglongint factorial( unsignedint number );
int main ( void )
{
unsignedint i;
for ( i = 0; i <= 40; i+=2)
{
printf( "%u! =%llu\n", i, factorial( i ));
}
}
unsignedlonglongint factorial( unsignedint number )
{
if ( number <= 1 ) {
return 1;
}
else
{
return ( number * factorial ( number - 1 ) );
}
}
To do the factorial of a number, you only need to do:
1 2 3 4 5 6 7 8 9 10
int x, i;
unsignedlonglong f; //Note that this will not be big enough to store the latter values.
for(x = 2;x <= 40; x = x + 2) //For each even number.
{
f = 1;
for(i = x; i > 0;--i)
{
f = f * i; //This will calculate the factorial of the number.
}
}
Also, even a 128 bit long long is not enough to store the value of 40!, so you need to use (or implement yourself) a bigint library.
And in answer to your posted question, you could use getchar() to cause the program to pause.