Q. 25. Write a Program to check whether a given number is prime or not.

Solution.
INTEGER NUMBER, TRY

READ *, NUMBER

DO 10 TRY = 2, NUMBER/2

IF( MOD(NUMBER,TRY).EQ.0) THEN
PRINT *, NUMBER,’ IS NOT A PRIME’
STOP
ENDIF

10     CONTINUE

PRINT *, NUMBER ,'IS A PRIME' STOP
END

Q. 26. X is an integer array of N elements (N = 10). Cyclically permute the values of X so that X1 contains the original value of X2, X2 contains the value X3 and so on, with XN containing the original value of X1.

Solution.
PARAMETER (N = 10)

INTEGER X(N)
INTEGER TEMP

READ *, X

C     SAVE THE FIRST ELEMENT

TEMP = X(1)

C     SHIFT LEFT BY 1 ELEMENTS X(2) THROUGH X (N)

DO 10 I = 2, N
X(I-1) = X(I)
10     CONTINUE

C     RESTORE SAVED VALUE OF FIRST ELEMENT IN THE LAST

X(N) = TEMP
PRINT *, X

STOP
END



Main Contents Page

© Universal Teacher Publications