IDENTIFICATION DIVISION.
PROGRAM-ID. 168C.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC X(100).
01 A          PIC 9(04).
01 B          PIC 9(04).
01 H          PIC 9(02).
01 M          PIC 9(02).
01 W          PIC 9(08)       COMP.
01 AK         PIC 9(04)V9     COMP.
01 BK         PIC 9(04)       COMP.
01 SK         PIC 9(04)V9     COMP.
01 CNT        PIC 9(05)V9(10) COMP.
01 OT1        PIC ZZZZ9.
01 OT2        PIC 9V9(17).
01 OUT        PIC ZZZZ9.9(10).
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO A B H M.
*>
  COMPUTE AK = H * 30 + M * 0.5.
  COMPUTE BK = M * 6.
  COMPUTE SK = AK - BK.
  IF (SK > 180)
    COMPUTE SK = 360 - SK
  END-IF.
*>
  DISPLAY function sqrt((A ** 2 + B ** 2) - (2 * A * B * FUNCTION COS(SK * 3.1415926536 / 180)))
*>
  STOP RUN.
