# Solved: HOW TO MULTIPLY TWO INTEGERS

Sure, I’ll write an article on “How to Multiply Two Integers in COBOL”

Multiplication of integers is a fundamental mathematical operation and forms a core aspect of almost every program we write in COBOL. Whether it’s creating a multiplication table or performing bulk data operation, the multiplication functionality plays a pivotal role. Let’s delve into the method of multiplying two integers in the world of COBOL programming language.

IDENTIFICATION DIVISION.
PROGRAM-ID. Multiplier.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUM-A PIC 9(3) VALUE 0.
01 NUM-B PIC 9(3) VALUE 0.
01 RESULT PIC 9(4) VALUE 0.
PROCEDURE DIVISION.
MULT START.
DISPLAY “Enter first integer:”.
ACCEPT NUM-A.
DISPLAY “Enter second integer:”.
ACCEPT NUM-B.
MULTIPLY NUM-A BY NUM-B GIVING RESULT.
DISPLAY “Result of multiplication: “, RESULT.
STOP RUN.

## Understanding the Multiplication Code

COBOL’s simplistic, English-like structure makes it easy to read and understand. In our code, we have our ‘IDENTIFICATION DIVISION’ followed by ‘PROGRAM-ID’ which is the name of our program. Then we move into the ‘DATA DIVISION’ where we define our two input variables NUM-A and NUM-B along with RESULT to store the product of multiplication.

Under ‘PROCEDURE DIVISION’ we have our main code. It begins with displaying to accept two integer values. ‘ACCEPT’ statement is used to read the input from the user. Then we perform the actual multiplication with the ‘MULTIPLY’ operation. ‘BY’ keyword is used to signify the second factor and the result of the multiplication is stored in RESULT by the ‘GIVING’ keyword. Finally, the product of multiplication is displayed.

## COBOL Libraries for Performing Multiplication

COBOL does not have library support like modern languages such as Python or Java. However, it does come with an extensive set of pre-defined functionalities embedded in the language itself. The ‘MULTIPLY’ function that we used in our code is one such built-in functionality. It supports multiplying multiple numbers in a single statement too.

In situations requiring more complex mathematical computation, programmers often write their own subprograms or call system routines provided by the OS or middleware.

## Similar Arithmetic Operations in COBOL

In addition to ‘MULTIPLY’, COBOL supports a host of other arithmetic operations. Here’s a brief look at them: