factorial of a number in rexx using internal procedure



Post anything related to mainframes (IBM & UNISYS) if not fit in any of the above categories

factorial of a number in rexx using internal procedure

Postby nalinigoli » Mon Aug 16, 2010 6:23 pm

Hi
/* factorialProgram.rex -- computes the factorial of a number */

/* Usage: exec factorialProgram number */

/* Example: exec factorialProgram 5 */

arg N .

call factorial N

say result

exit 0 /* don't fall through to the PROCEDURE instruction */

/* internal procedure FACTORIAL
* returns factorial of argument N
*/

factorial : PROCEDURE

n = arg( 1 )

if n = 1 then
return 1

return n * factorial( n - 1 )


i have given in my pds member and execcuted using the command in the ispf panel " tso exec rexx.exec(main1) exec"
rexx.exec(main1) is the dataset where i have stored the above rexx code
please help me on how to execute this
if i try this it is showing error in the line exit 0
nalinigoli
 
Posts: 3
Joined: Mon Aug 16, 2010 6:15 pm
Has thanked: 0 time
Been thanked: 0 time

Re: factorial of a number in rexx using internal procedure

Postby MrSpock » Mon Aug 16, 2010 8:04 pm

tso exec rexx.exec(main1) exec

Why are you passing the argument 'exec' and not a number?

Also, post some real TRACE command runtime output.
User avatar
MrSpock
Global moderator
 
Posts: 809
Joined: Wed Jun 06, 2007 9:37 pm
Location: Raleigh NC USA
Has thanked: 0 time
Been thanked: 4 times

Re: factorial of a number in rexx using internal procedure

Postby NicC » Mon Aug 16, 2010 8:30 pm

And why are you posting here and not the rexx forum?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: factorial of a number in rexx using internal procedure

Postby enrico-sorichetti » Mon Aug 16, 2010 8:31 pm

And why are you posting here and not the rexx forum?

because he wants suggestions and feedback... what else 8-)
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: factorial of a number in rexx using internal procedure

Postby nalinigoli » Tue Aug 17, 2010 10:46 am

[quote="nalinigoli"]Hi

/* main1 rexx*/
/* call factor sub program****/
pull x
say x
arg x
call factor x
say result
exit 0
factor:PROCEDURE
x = arg(1)
if x = 1
then return 1
return x * factor(x-1)

if i try this it is showing error
13 +++ return x * factor(x-1)
6 +++ call factor x
Error running MAIN1, line 13: Bad arithmetic conversion

please help me out
nalinigoli
 
Posts: 3
Joined: Mon Aug 16, 2010 6:15 pm
Has thanked: 0 time
Been thanked: 0 time

Re: factorial of a number in rexx using internal procedure

Postby NicC » Tue Aug 17, 2010 2:50 pm

Your trace is not showing the values - only the statements being executed. Try TRACE '?i' for a full interactive trace. SAY the value of x before executing line 13.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: factorial of a number in rexx using internal procedure

Postby NicC » Tue Aug 17, 2010 3:59 pm

What value for x are you testing with? I have tried the code you originally posted and it is giving me good results up to x = 4 so I would sugest that it is ok.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: factorial of a number in rexx using internal procedure

Postby NicC » Tue Aug 17, 2010 4:07 pm

One other thing - the code does not handle invalid input! x < 1 goes into an endless loop!
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: factorial of a number in rexx using internal procedure

Postby nalinigoli » Tue Aug 17, 2010 4:33 pm

can u pls give me the exact code u have executed
nalinigoli
 
Posts: 3
Joined: Mon Aug 16, 2010 6:15 pm
Has thanked: 0 time
Been thanked: 0 time

Re: factorial of a number in rexx using internal procedure

Postby NicC » Tue Aug 17, 2010 4:47 pm

As I wrote 3 posts before
I have tried the code you originally posted
i.e. I cut and pasted it, loaded it to the mainframe and executed it. Afterwards I prettied it up, added the check for the parm being greater than zero and reformatted it to my own standards but what I executed first is the exact code you originally posted.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Next

Return to All other Mainframe Topics

 


  • Related topics
    Replies
    Views
    Last post