PHYSICS 580 Spring 2005
Fortran Example #4 due
Write a program to compute the combinatorial
. The program will
request the input of two integers and print out the combinatorial as a real
number
The program will consist of two parts, a main program and a subroutine that actually computes the combinatorial.
The two numbers N and k should be passed as integers to the subroutine. However, to make computing easier, rather than computing the factorial, compute the log factorial,
log N ! = sum( i = 2,N) log i
and then log
log N !– log k ! – log (N-k)!;
finally exponentiate the answer. You may leave it as a real number.
Your subroutine should have error traps for the following: N or k < 0, and N < k. In case of an error, it should return a logical variable.
The main calling program should ask for two integer and then call the subroutine. It should check the
error flag; if there is an error, print an error message; if not, print the
result.
To make identification easier for me please use the convention lastname_ex4.f for your program. Also, your program should print out the following at the beginning:
This is fortran example 4.
Written by your name here.
to submit: first compress your file (this will help save formatting)
gzip lastname_ex4.f
this will produce a file lastname_ex4.f.gz
attach this to an e-mail to: cjohnson@sciences.sdsu.edu