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         COMP-2.
01 BK         COMP-2.
01 SK         COMP-2.
01 COS2       COMP-2.  
01 CNT        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 COS2 = FUNCTION COS(SK * 3.14159265358979324 / 180).
  if ((A ** 2 + B ** 2) - (2 * A * B * COS2) < 0.01)
    COMPUTE CNT = function sqrt(((A ** 2 + B ** 2) - (2 * A * B * COS2)) * 100) / 10    
    DISPLAY CNT
  else
    DISPLAY function sqrt((A ** 2 + B ** 2) - (2 * A * B * COS2))    
  END-if.
*>
  STOP RUN.
