COCS3308 Program-4 (FORTRAN-1) Due: 10/18/2006 Combination Calculation Task; Write a FORTRAN program that does: 1. calculate all combinations of 3, 4, ..., 8 values out of 9 numbers, 1,2,3,4,5,..., 9. 2. and print all these combinations. Suggestions: Use two subroutines: Printing and Combinations given below: Subroutine Printing Integer Comb(300,9), Many, Count Common Comb, Many, Count C Subroutine body follows Write(6,100) Many, Count 100 Format ('1', '# of values := ', I4, '# of combinations :=', I4) Do 200 i = 1, Count Write (6, 300) ( Comb(i,j), j=1,Many) 300 FORMAT (' ', 9I4) 200 Continue End !!! End of subroutine Printing Subroutine Combinations C CALCULATING COMBINATIONS OF NUMBERS, UP TO 9 NUMBERS C IMPLICIT INTEGER (A-Z) INTEGER COMB(300,9) LOGICAL MORE COMMON COMB,MANY,COUNT COUNT=1 DO 100 M=1, MANY 100 COMB(COUNT,M)=M ! THE FIRST COMBINATION: 1,2,3,...,MANY C C SET UP AN INFINITE LOOP IN WHICH TO PICK UP THE NEXT COMBINATION C MORE = .TRUE. DO WHILE (MORE) MORE= .FALSE. !!! ASSUME THAT NO MORE COMBINATION IS TO BE FOUND !!! DO 200 M=MANY,1,-1 IF (.NOT. MORE .AND. (COMB(COUNT,M) .LT. 9-MANY+M)) Then MORE = .true. Last = M End if 200 CONTINUE IF (MORE) THEN COUNT=COUNT+1 DO 500 N=1, Last-1 500 COMB(COUNT,N)=COMB(COUNT-1,N) KEEP=COMB(COUNT-1,Last) DO 600 N=Last,MANY KEEP=KEEP+1 600 COMB(COUNT,N) = KEEP END IF ! END OF IF (MORE) END DO ! END OF THE INFINITE LOOP !!!!!!!!!!!!! END