MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

square and cube functions in COBOLsquare and cube functions

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
mfuser
Banned


Joined: 01 Mar 2005
Posts: 105
Topics: 58

PostPosted: Mon Nov 06, 2006 2:08 pm    Post subject: square and cube functions in COBOLsquare and cube functions Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Nov 06, 2006 3:03 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group