Practice problem

 

DO NOT TURN IN

 

Write a short program to compute the double factorial, 

 

N !! = N (N-2) (N-4) (N-6) ... 2 or 1, depending if N is even or odd.  You may do this either in the body of the program or in a subroutine.

 

Both N and N !! should be a regular integer (so declared integer, not integer*8).

 

Now write a loop over N and find out when machine precision makes N !! unreliable. This can be recognized when you increase N by 1 but the result for N !! is smaller. This is because of overrun.

 

Your assignment is to write a program to automatically find the maximal value of N before machine precision kills your routine. That is, it should loop over increasing N until the value of N !! actually decreases.   Hint: you will have to store your previous value of N !! from the previous loop. You will also have to initially this “old” value to 1 before you start your loop.

 

If you can finish this successfully in under 1 hour, then you have good programming skills.

If you can finish this project successfully, but it takes you significantly longer than 1 hours, you need more practice.

If you cannot solve this problem at all, you have serious deficiencies and need to work much harder to improve your programming skills.

 

DO NOT TURN IN -- FOR YOUR PRACTICE ONLY