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.
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% 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.
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.