Q. 31. Write a FORTRAN program which finds all three
digit prime numbers. (Dec. 99)
Solution.
INTEGER N, K, M
10 DO 40 N = 100, 999
K = 2
M = SQRT (N)
20 IF (MOD (N, K) .EQ. 0) GOTO 10
K = K + 1
IF (K .LE. M) THEN GOTO 20
WRITE (*, 30) N
30 FORMAT(1X, I5, 'IS A PRIME
NUMBER')
40 CONTINUE
STOP
END
Q. 32. Write a FORTRAN subroutine that computes
the sum of square of the minimum and cube of the maximum
of an array of N natural numbers, and prints out the
value with suitable message. (June
2000)
Solution.
SUBROUTINE TOT (A, N, SUM)
REAL A(N),SUM, MAX, MIN
INTEGER I, N
SUM = 0.0
MAX = A(1)
MM = A(1)
DO 10 I = 2, N
IF (A(I) .GT. MAX) MAX = A(I)
IF (A(I) .LT. MIN) MIN = A(I)
10 CONTINUE
SUM = SUM + MIN * * 2 + MAX * * 3
WRITE (*, 15) SUM
15 FORMAT(1X, 'THE SUM OF
SQUARE OF MIN AND CUBE OF MAX=', F5.2)
STOP
END
|