Showing posts with label Arithmatic operations in cobol. Show all posts
Showing posts with label Arithmatic operations in cobol. Show all posts

Saturday, 15 September 2012

Arithmetic operatins

                         How multiplication operations take place in COBOL?
Multiply var-1 by var-2. Or
If you want to store the result in specific variable then use GIVING clause.
Multiply var-1 by var-2 giving var-3.
This will not overrides var-2 values.
Program:



Output:

If we want to multiply same variable by two or more  variables then use below Program:
Syntax:
MULTIPLY A by B C


 
Output:

Below will not work












                     How division operation take place in COBOL?
Syntax:
DIVIDE var-1 INTO var-2 var-3 var-4

If var-1 = 56 and var-2 = 04 then it means perform the operation 56/2 and stores result in Var-1.
or
If you want to store the result in specific variable then use GIVING clause.
DIVIDE var-1 INTO var-2 giving var-3.
Program:
  

Output:




Will it gives remainder also?
Now I will change the value of variable A and submit the job again.
 





Output:

It will gives you only quotient of operation not remainder.