View previous topic :: View next topic |
Author |
Message |
mfuser Banned
Joined: 01 Mar 2005 Posts: 105 Topics: 58
|
Posted: Mon Nov 06, 2006 2:08 pm Post subject: square and cube functions in COBOLsquare and cube functions |
|
|
Members,
Is there any function in COBOL which will retrieve square as well cube of any number and how to represent the notations in the calculations ?
For example:
8 square = 64
8 cube = 512 |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Nov 06, 2006 3:03 pm Post subject: |
|
|
mfuser,
Exponentiation in cobol is denoted by ** operator. So square = n to power of 2 and cube is n to the power of 3. ( n = number)
check this
Code: |
01 WS-INP-NUM PIC S9(09) COMP VALUE 8.
01 WS-SQUARE PIC S9(15) COMP-3.
01 WS-CUBE PIC S9(15) COMP-3.
PROCEDURE DIVISION.
COMPUTE WS-SQUARE = WS-INP-NUM ** 2
DISPLAY 'THE SQUARE IS : ' WS-SQUARE
COMPUTE WS-CUBE = WS-INP-NUM ** 3
DISPLAY 'THE CUBE IS : ' WS-CUBE
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
|
|