0

在fortran中使用do循环时遇到问题,

REAL W,V,X 
DO 50 W = 0.5,5.0,0.5
DO 50 V = 10.0,1000.0,10.0
DO 50 X = 1.0,10,1.0
C=(W*V*X)/1000.0
WRITE(*,*) W,V,X,C
50 CONTINUE
STOP
END 

如果我给出了这个,它表明在 do 循环中只需要使用整数,有没有办法在 do 循环中给出整数或任何其他方式来做到这一点?

4

2 回答 2

6

使用整数作为循环索引

      REAL W,V,X
      INTEGER I,J,K

      DO 50 I = 1,10
        DO 50 J = 1,100
          DO 50 K = 1,10

            W = 0.5 * I
            V = 10.0 * J
            X = 1.0 * K

            C=(W*V*X)/1000.0
            WRITE(*,*) W,V,X,C

50    CONTINUE
      STOP
      END
于 2013-06-13T17:04:09.707 回答
0

You should be able to accomplish the same thing by incrementing a real variable by adding your step value, and using an if then to exit the loop. Clunky, but should work.

The last time I programmed in Fortran, I used punch cards and an IBM-360, so I'm not going to pretend I remember the syntax.

于 2013-06-13T17:17:42.280 回答