Background
[wp_ad_camp_5]
This article demonstrates how to perform basic arithmetic in COBOL.
Software Environment
- Windows 7 Professional SP1
- Visual COBOL for Eclipse Personal Edition 2.2 by Micro Focus
- Java 1.7 (1.7.0_67 – Windows x86)
Basic Arithmetic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | program-id. arithmetic as "arithmetic". environment division. configuration section. data division. working-storage section. 01 X PIC 9999. 01 Y PIC 9999. 01 RESULT PIC 9999. 01 X_D PIC ZZZZ. 01 Y_D PIC ZZZZ. 01 RESULT_D PIC ZZZZ. procedure division. MOVE 10 TO X. MOVE 5 TO Y. MOVE X TO X_D. MOVE Y TO Y_D. MULTIPLY X BY Y GIVING RESULT. MOVE RESULT TO RESULT_D. DISPLAY X_D, " * ", Y_D, " = ", RESULT_D. DIVIDE X BY Y GIVING RESULT. MOVE RESULT TO RESULT_D. DISPLAY X_D, " / " , Y_D, " = ", RESULT_D. ADD X Y GIVING RESULT. MOVE RESULT TO RESULT_D. DISPLAY X_D, " + ", Y_D, " = ", RESULT_D. SUBTRACT X FROM Y GIVING RESULT. MOVE RESULT TO RESULT_D. DISPLAY X_D, " - ", Y_D , " = ", RESULT_D. goback. end program arithmetic. |
Sample Output
[wp_ad_camp_4]
Download the Project
https://www.dropbox.com/s/3eed8x7p7aq5r8p/turreta%20arithmeric.zip?dl=0
[wp_ad_camp_3]