Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created April 18, 2020 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/eacd3b2f539be3d85bb34db85733f656 to your computer and use it in GitHub Desktop.
Save jasongorman/eacd3b2f539be3d85bb34db85733f656 to your computer and use it in GitHub Desktop.
IDENTIFICATION DIVISION.
PROGRAM-ID. SQRT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 prev PIC 9(08)V9(12) VALUE ZEROES.
LINKAGE SECTION.
01 num PIC 9(08)V9(12).
01 root PIC 9(08)V9(12) VALUE ZEROES.
PROCEDURE DIVISION USING num, root.
MAIN-PROCEDURE.
COMPUTE root = num / 2
PERFORM GUESS UNTIL root = prev
STOP RUN.
GUESS.
MOVE root TO prev
COMPUTE root = (root + (num/root))/2
GOBACK.
END PROGRAM SQRT.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment