Sha256: 2581f10869770c284db071daf35c662eff68f27e0331beed726c33130408054a

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

       IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Arithmetic.

       DATA DIVISION.
       WORKING-STORAGE SECTION.

       01 A      PIC S9(10).
       01 B      PIC S9(10).
       01 Result PIC S9(10).

       PROCEDURE DIVISION.
           DISPLAY "First number: " WITH NO ADVANCING
           ACCEPT A
           DISPLAY "Second number: " WITH NO ADVANCING
           ACCEPT B
           
*          *> Note: The various ADD/SUBTRACT/etc. statements can be
*          *> replaced with COMPUTE statements, which allow those
*          *> operations to be defined similarly to other languages,
*          *> e.g. COMPUTE Result = A + B

           ADD A TO B GIVING Result
           DISPLAY "A + B = " Result

           SUBTRACT B FROM A GIVING Result
           DISPLAY "A - B = " Result

           MULTIPLY A BY B GIVING Result
           DISPLAY "A * B = " Result

*          *> Division here truncates towards zero. DIVIDE can take a
*          *> ROUNDED clause, which will round the result to the nearest
*          *> integer.
           DIVIDE A BY B GIVING Result
           DISPLAY "A / B = " Result

           COMPUTE Result = A ^ B
           DISPLAY "A ^ B = " Result
       
*          *> Matches sign of first argument.
           DISPLAY "A % B = " FUNCTION REM(A, B)

           GOBACK
           .

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
zettacode-0.1.7 files.zettacode/arithmetic.integer/cobol.txt
zettacode-0.1.6 files.zettacode/arithmetic.integer/cobol.txt
zettacode-0.1.6 files.zettacode2/arithmetic.integer/cobol.txt
zettacode-0.1.5 files.zettacode/arithmetic.integer/cobol.txt
zettacode-0.1.5 files.zettacode2/arithmetic.integer/cobol.txt
zettacode-0.1.4 files.zettacode/arithmetic.integer/cobol.txt
zettacode-0.1.4 files.zettacode2/arithmetic.integer/cobol.txt
zettacode-0.1.3 files.zettacode/arithmetic.integer/cobol.txt
zettacode-0.1.2 files.zettacode/arithmetic.integer/cobol.txt
zettacode-0.1.1 zettacode.files/arithmetic.integer/cobol.txt