Q. 9. Write each of the following
statements in FORTRAN: (Dec.
2001)
(i) If R = 2S + T, go to statement labelled 87
(ii) If S ¹ 11, go
to statement labelled 44
(iii) If 3S > 4T, stop
Ans. (i) IF (R .EQ. (2 * S +
T)) GOTO 87
Ans. (ii) IF (S .NE. 11) GOTO 44
Ans. (iii) IF (3 * S .GT. 4 * T) STOP
Q. 10. For J = 2 and K = 5, find
the final values of J and K after each program segment:
(June 2001)
(i) If (J - K) 10, 10, 20
10 J = K
20 J = J + 2
(ii) IF (J .GE. K) J = K + 2
J = J + 2
Ans. (i) J = 5 and K = 5
Ans. (ii) J = 4 and K = 5
Q. 11. Suppose J and K contain respectively
3 and 5. Find the final values of J and K after each
program segment: (Jan. 2001)
If (J .EQ. K) J = J + 2
J = J + 2
IF (J .GE. K + 1) GOTO 10
J = J + 2
10 J = J + K
Solution.
Since J is not equal to k, it will remain unchanged.
J will be incremented by 2 and becomes 5.
The condition is false as J = 5 and K + 1 = 6.
J will be incremented by 2 and becomes 7.
J will be incremented by the value of K(5) and becomes
12.
Therefore, the final values of J and K are 12 and
5 respectively.
Q. 12. Write the following statements
in FORTRAN: (June 2000)
(i) If P = 2Q + 3, go to statement labelled 45
(ii) If 2P > 3Q, stop
(iii) If J ¹ 7, go
to statement labelled 32
Ans. (i) IF (P .EQ. (2 * Q +
3)) GOTO 45
Ans. (ii) IF (2 * P .GT. 3 * Q) STOP
Ans. (iii) IF (J .NE. 7) GOTO 32
|