Make your own free website on Tripod.com

         Home   Table of Content
Nested      Control       Structure

p198    FIGURE 4.18   Nested Loops

       PROGRAM NESTED

C  ILLUSTRATES NESTED LOOPS

C  DECLARATIONS

       INTEGER M, N

       PARAMETER (M=3, N=2)

       INTEGER I, J

 

C Display table of values for I and J

       Print  *,            I                J

        DO 10  I= 1 , M

           PRINT *, OUTER , I

               DO 20  J= 1, N

                      PRINT * ,  INNER , I , J

  20         CONTINUE           
  10   CONTINUE

        STOP
        END

 

                 I              J

OUTER         1

   INNER       1              1

   INNER       1              2

OUTER          2

   INNER        2             1

   INNER        2             2

OUTER          3           

   INNER        3             1

   INNER        3              2

    

P.177  

         CASE STUDY: APPROXIMATING VALUE OF e

 

p.179 參閱Figure 4.9      Finding value of e

       由於為求精簡,  以後只呈現最重要的部分

          TERM=1.0

          E=1.0

          DO 10 I= 1, N

             TERM = TERM/I

             E=E+TERM

     10   CONTINUE

 

    推算原理     E          TERM

                        1                 1   
                        1              1/2

                    1+1/2           1/2*1/3

        1+(1/2)+(1/2*1/3)     以此類推

WHILE LOOP

P.185       DO WHILE  (N .NE. 0)

                            PRINT *,  ENTER N=
READ *,  N

                END DO

 

P.187   INTEGER MAXPOW

            PARAMETER (MAXPOW=1000)

               .

            READ *, N

               .
        NEXPOW = 1

            DO WHILE (NEXPOW  .LT.  MAXPOW)

                 PRINT *,  NEXPOW

                 NEXPOW = NEXPOW * N

            END DO

Top of this Page