0% found this document useful (0 votes)
45 views

Sum of Digits

The COBOL program takes two numbers as input, divides each number by 10 to separate the digits, adds the digits together, and displays the sum. When run with the input of 456, it correctly displayed the sum of digits as 15. The program uses common COBOL elements like DATA DIVISION to define variables, PROCEDURE DIVISION for the logic, and ACCEPT and DISPLAY to get input and output.

Uploaded by

Kunal Bose
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Sum of Digits

The COBOL program takes two numbers as input, divides each number by 10 to separate the digits, adds the digits together, and displays the sum. When run with the input of 456, it correctly displayed the sum of digits as 15. The program uses common COBOL elements like DATA DIVISION to define variables, PROCEDURE DIVISION for the logic, and ACCEPT and DISPLAY to get input and output.

Uploaded by

Kunal Bose
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

NAME KUNAL BOSE ROLL 06 MCA 1ST YEAR 2ND SEMESTER COBOL ASSIGNMENT COMPUTE THE SUM OF TWO

TWO NUMBERS DISPLAY THE SUM.


-------------------------------------------------------------------IDENTIFICATION DIVISION. PROGRAM-ID. SUMOFDIGITS. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 N PIC 9(5). 77 N1 PIC 9(5). 77 P PIC 9(5). 77 P2 PIC Z(4). PROCEDURE DIVISION. MAIN. DISPLAY "ENTER THE NUMBER:". ACCEPT N. PERFORM P1 UNTIL N=0. MOVE P TO P2. DISPLAY "SUM OF DIGITS: " P2. STOP RUN. P1. DIVIDE N BY 10 GIVING N REMAINDER N1. ADD P N1 GIVING P.

OUTPUT
--------------------------------------------------

C:\cobol85>COBOL3 DIGITSUM.COB C:\cobol85>CRUN3 DIGITSUM 456 SUM OF DIGITS: 15 C:\cobol85>

You might also like