Q. 19. Write a program that reads a four-digit number and finds the sum of the individual digits.

Solution.
INTEGER DIGIT1, DIGIT2, DIGIT3, DIGIT4, SUM

READ *, N

DIGIT1 = N - (N/10)*10
N = N/10

DIGIT2 = N - (N/10)*10
N = N/10

DIGIT3 = N - (N/10)*10
N = N/10

DIGIT4 = N
SUM = DIGIT1 + DIGIT2 + DIGIT3 + DIGIT4

PRINT *, SUM

STOP
END

Q. 20. Write a program to find out the largest of the given three numbers.

Solution.
REAL X1, X2, X3
READ *, X1, X2, X3

IF (X1 .GT. X2) THEN
IF (X1 .GT. X3) THEN
PRINT *, X1
ELSE
PRINT *, X3
ENDIF
ELSE
IF (X2 .GT. X3) THEN
PRINT *, X2
ELSE
PRINT *, X3
ENDIF

ENDIF

STOP
END



Main Contents Page

© Universal Teacher Publications