sign in
 
   
 
 
 
   
  COBOL TUTORIAL FOR BCA STUDENTS OF M G UNIVERSITY  
  UNIT 4: PROCEDURE DIVISION . . .  
   
     
  DIVIDE VERB  
 

The purpose of this verb is to divide one number by another and to store the result.

There are several forms of this verb. One of its forms is as follows:

 
 


 
 

Examples:

 
 

DIVIDE 5 INTO A.

 
 

If the value of A is 20, then after the execution of this statement the value of A will be 4. The old value of A will be lost.

 
 

DIVIDE 5 INTO A GIVING B.

 
 

If the value of A is 20, then after the execution of this statement the value of B will be 4. Here A will retain its old value.

 
 

DIVIDE 3 INTO A GIVING B C.

 
 

Here the result of the division of A by 3 will be stored both in B and C.

 
  DIVIDE 2.5 INTO A B GIVING C D.  
 

In this case A will be divided by 2.5 and the result will be stored in C, whereas the result of the division of B by 2.5 will be stored in D.

 
 

As in the case of the MULTIPLY statement, literals cannot be used for identifier-2, identifier-3, etc. Only when the GIVING option is used the numeric literals permitted in place of identifier-2, identifier-3, etc.

For example:

DIVIDE A INTO 25 GIVING B.

 
   
 

The second form of this verb is as follows:

 
   
 

In this case identifier-1 or numeric-literal-1 will be divided by identifier-2 or numericliteral- 2, whatever may be the case. The result is stored in identifier-3, identifier-4, etc.

Examples:

 
  DIVIDE A BY 3 GIVING C.  
 

If the value of A is 21 then after the execution of this statement C will contain 7.

 
   
 

There is another form of DIVIDE verb where there is a provision to store the remainder.

 
     
 
Example:

 
  DIVIDE A INTO B GIVING C REMAINDER D.  
 

If the identifier A, B, C and D are all two-digited numbers and if they contain 05, 37, 18 and 20 respectively before the execution of the statement, then after the execution of the statement, they will contain 05, 37, 07 and 02 respectively.