Help with program

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.

Please and thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <stdio.h>



unsigned long long int factorial( unsigned int number );

int main ( void )
{
unsigned int i;

for ( i = 0; i <= 40; i+=2)
{ 
printf( "%u! =%llu\n", i, factorial( i ));
}
}

unsigned long long int factorial( unsigned int 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; 
unsigned long long 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.
closed account (o3hC5Di1)
For a thread dedicated to the problem of your console closing down, please see: http://www.cplusplus.com/forum/beginner/1988/

All the best,
NwN
Thanks guys, i got it to stop and the program works!
Topic archived. No new replies allowed.