- #1
- 8
- 1
small FORTRAN code for combinations. BUG!
for n=4,r=2
prints
For any n it prints and extra line once for r=2.
For r=3 it prints extra twice.
can anyone help?
Code:
PROGRAM test
implicit double precision(a-h,o-z)
INTEGER :: r=2,n=4,k=1
INTEGER,allocatable :: comb(:) !array to hold a set of combinations
allocate(comb(r))
comb(1)=1
CALL iterate(1,n-r+1,1)
CONTAINS
RECURSIVE SUBROUTINE iterate(s,e,j)
INTEGER,INTENT(IN) :: s,e
DO i=s,e
comb(j)=i
if(j.LT.r) then
CALL iterate(i+1,e+1,j+1)
END IF
WRITE(*,*)comb
END DO
END SUBROUTINE iterate
END PROGRAM test
for n=4,r=2
prints
1 2
1 3
1 4
1 4 <-here
2 3
2 4
2 4 <-here
3 4
3 4 <-here
For any n it prints and extra line once for r=2.
For r=3 it prints extra twice.
can anyone help?
Last edited by a moderator: