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 AK         PIC 9(04)V9.
01 BK         PIC 9(04).
01 SK         PIC 9(04)V9.
01 COSI       COMP-2.  
*>
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.
*>
  COMPUTE COSI = FUNCTION COS(SK * 3.14159265358979324 / 180).
  DISPLAY function sqrt((A ** 2 + B ** 2) - (2 * A * B * COSI)).
*>
  STOP RUN.
