Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

Divides one or more operands by another and stores the result in one or more data

Posted By: Hailey Campbell     Category: Cobol     Views: 2262

Divides one or more operands by another and stores the result in one or more data.

* DIVIDE A BY B GIVING C means C = A / B
* DIVIDE A INTO B GIVING C means C = B / A

Code for Divides one or more operands by another and stores the result in one or more data in Cobol

IDENTIFICATION DIVISION.
PROGRAM-ID. TEST_DIVIDE.

DATA DIVISION.
WORKING-STORAGE SECTION.
77 NUM-02                   PIC S9(8).
77 NUM-03                   PIC S9(11)V9(3) COMP.
77 NUM-04                   PIC S9(10)V9(4) COMP.

77 EDI-01                   PIC --,---,---,--9.999.

PROCEDURE DIVISION.
MAIN.

*   DIVIDE ope1 BY ope2 GIVING ope3 REMAINDER
    DISPLAY "DIVIDE 8 BY 3 GIVING " WITH NO ADVANCING
    DIVIDE 8 BY 3 GIVING NUM-02 REMAINDER NUM-03
    MOVE NUM-02 TO EDI-01 DISPLAY EDI-01 WITH NO ADVANCING
    MOVE NUM-03 TO EDI-01 DISPLAY ", REMAINDER " EDI-01

*   DIVIDE ope1 BY ope2 GIVING ope3 REMAINDER
    DISPLAY "DIVIDE 8 BY 3 GIVING " WITH NO ADVANCING
    DIVIDE 8 BY 3 GIVING NUM-03 REMAINDER NUM-04
    MOVE NUM-03 TO EDI-01 DISPLAY EDI-01 WITH NO ADVANCING
    MOVE NUM-04 TO EDI-01 DISPLAY ", REMAINDER " EDI-01

*   DIVIDE ope1 BY ope2 GIVING ope3 ope4 ope5
    DISPLAY "DIVIDE 60072916306 BY 260663 GIVING "
    DIVIDE 60072916306 BY 260663 GIVING NUM-02 NUM-03, NUM-04
    MOVE NUM-02 TO EDI-01 DISPLAY EDI-01 WITH NO ADVANCING
    MOVE NUM-03 TO EDI-01 DISPLAY ", " EDI-01 WITH NO ADVANCING
    MOVE NUM-04 TO EDI-01 DISPLAY ", " EDI-01

*   DIVIDE ope1 INTO ope2, ope3, ope4
    DISPLAY "DIVIDE 3 INTO " WITH NO ADVANCING
    DISPLAY NUM-02 ", " NUM-03 ", " NUM-04 "= "
    DIVIDE 3 INTO NUM-02, NUM-03, NUM-04
    MOVE NUM-02 TO EDI-01 DISPLAY EDI-01 WITH NO ADVANCING
    MOVE NUM-03 TO EDI-01 DISPLAY ", " EDI-01 WITH NO ADVANCING
    MOVE NUM-04 TO EDI-01 DISPLAY ", " EDI-01

*   DIVIDE ope1 INTO ope2 GIVING ope3 ope4 ope5
    DISPLAY "DIVIDE 260663 INTO 60072916306 GIVING "
    DIVIDE 260663 INTO 60072916306 GIVING NUM-02 NUM-03, NUM-04
    MOVE NUM-02 TO EDI-01 DISPLAY EDI-01 WITH NO ADVANCING
    MOVE NUM-03 TO EDI-01 DISPLAY ", " EDI-01 WITH NO ADVANCING
    MOVE NUM-04 TO EDI-01 DISPLAY ", " EDI-01

    STOP RUN
    .
* =================================================================

* The result is:

* DIVIDE 8 BY 3 GIVING              2.000, REMAINDER              2.000
* DIVIDE 8 BY 3 GIVING              2.666, REMAINDER              0.002
* DIVIDE 60072916306 BY 260663 GIVING
*        230,462.000,        230,462.000,        230,462.000
* DIVIDE 3 INTO +00230462, +00000230462000, +00002304620000=
*         76,820.000,         76,820.666,         76,820.666
* DIVIDE 260663 INTO 60072916306 GIVING
*        230,462.000,        230,462.000,        230,462.000
  
Share: 



Hailey Campbell
Hailey Campbell author of Divides one or more operands by another and stores the result in one or more data is from Toronto, Canada.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!