!Program name: LOGICAL
!Value of Ln 2
Logical done/.false./, even/.true./ ! first done and subsequent done values are false until either condition is met at the end of the code.
1 If (done) then ! first done and subsequent done values are false and the code goes to else
Print *, 'Iteration is over. Ln 2 is: ', X
XOLD=X !first X is zero (even number)
even= .not. even ! swap even and not even at each iteration
If (even) X=X-(1./float(I)) ! the second, fourth, sixth,... X values are computed here.
If (.not. even) X=X+(1./float(I)) !the first, third, fifth,... X values are computed here.
Print *, 'XOLD:', XOLD, 'I:', I, 'X:', X
done=(abs(X-XOLD) .lt. 0.01) .or. (I .ge. 100)
go to 1
Postar um comentário