FORTRAN Basics Quiz


Your Name:

1. Assuming the declarations

     INTEGER N
     REAL PI, ALPHA
put a check by each valid FORTRAN statement.
    (a) PI = 3.14159
    (b) N = N + 1
    (c) ALPHA = '1'
    (d) N + 1 = N

2. Classify each of the following as an Integer constant, a real constant, a character constant, or Not Valid.

(a) +3
Integer     Real     Character     Not Valid

(b) NAME
Integer     Real     Character     Not Valid

(c) 0.52E-10
Integer     Real     Character     Not Valid

(d) 'NAME'
Integer     Real     Character     Not Valid

(e) "NAME"
Integer     Real     Character     Not Valid

3. For the following segments of Fortran code, either an error will occur or value(s) will be stored. Assume default Fortran types for any variables that have not been explicitly declared.

a.

       CHARACTER*4 SUBJ
       SUBJ = 'OC3030'
OC3030     OC30     3030     Error. Nothing will be stored.

b.

       INTEGER I, J, K, L
       I = 3
       J = 3
       K = 5
       L = K * I / J**2 + .9
1     1.9     2     Error. Nothing will be stored.

c.

  
       REAL C, D, F
       C = 4 
       D = 2
       F = -C**2 * 1.0E+03 / 2.*D
  4000     -4000     16000     -16000     Error. Nothing will be stored.


4. Write a Fortran statement in each box provided to do the following:

a) set R to

b) set y equal to the cube root of x (calculate as x to the one-third power)

c) assign W the value

d) read in 2 real numbers, R and THETA from the user (keyboard) using list-directed (i.e. free format) input.