fibonacci series using rexx



IBM's Command List programming language & Restructured Extended Executor

fibonacci series using rexx

Postby supriya saraswat » Fri Aug 01, 2008 5:36 pm

i want fibonacci series program in rexx.
since i am just learner that's as an example i want that.

i want complete series for a number which has to be entered by user.
supriya saraswat
 
Posts: 21
Joined: Mon Jul 07, 2008 3:24 pm
Has thanked: 0 time
Been thanked: 0 time

Re: fibonacci series using rexx

Postby shivendu » Fri Aug 01, 2008 6:05 pm

Can you please what you mean by below
i want complete series for a number which has to be entered by user.

As far as I know Fibonacci series is f(x) = f(x-1) + f(x-2) like 0,1,1,2,3,5,8,13,18……….Do you mean one should give two consecutives like 8,13 and the remaining series is generated?

Thanks
Shvndu
shivendu
 
Posts: 11
Joined: Sun May 04, 2008 3:52 pm
Has thanked: 0 time
Been thanked: 0 time

Re: fibonacci series using rexx

Postby supriya saraswat » Mon Aug 04, 2008 11:47 am

no ...
i just want a program for fibonacci series .simple.
supriya saraswat
 
Posts: 21
Joined: Mon Jul 07, 2008 3:24 pm
Has thanked: 0 time
Been thanked: 0 time

Re: fibonacci series using rexx

Postby dick scherrer » Mon Aug 04, 2008 12:05 pm

Hello,

i just want a program for fibonacci series .simple.
Not until you properly define what you want.

We will not charge extra if you use more keystrokes to explain in more detail :)

The series can run to infinity and i suspect that is not what is needed. . .

Are you looking for a way to chart the spiral from the series? This would be non-trivial. . .

Keep in mind that you know exactly what you want while we all have different backgrounds and may not interpret your request as you intended.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: fibonacci series using rexx

Postby supriya saraswat » Tue Aug 05, 2008 11:48 am

actually i want to know how the concept of array can be used in rexx.

so as an example i took fibonacci series.e.g for a user entered number say 4 the output should come like 0 1 1 2 3 .

i have already tried to write that code in rexx please tell me that whether this is correct or not.
/* rexx */

parse arg n
last=n-1
x.0=0
x.1=1
do i=2 to last
x.i=x.(i-1) + x.(i-2)
end
do i=0 to last by +1
say x.i
end
supriya saraswat
 
Posts: 21
Joined: Mon Jul 07, 2008 3:24 pm
Has thanked: 0 time
Been thanked: 0 time

Re: fibonacci series using rexx

Postby krsk0101 » Fri Aug 29, 2008 1:02 pm

Hello,
Is that code working? Please let me know.....
krsk0101
 
Posts: 3
Joined: Thu Jul 10, 2008 12:47 pm
Has thanked: 0 time
Been thanked: 0 time

Re: fibonacci series using rexx

Postby Gilles » Mon Sep 29, 2008 6:38 pm

Hi,

The index of a stem needs to be resolved before using it. You cannot have something like X.(I-1). It wouldn't be recognized. You could store I-1 in another variable like J=I-1 just before and then using X.J to access it.

I think it's more fun to resolve these math problems with recursion. Something like the following where we compute the first 35 instances and store them in the array ARR.

/* We go up to that number */
LIMIT = 35

CALL FIBONACCI(LIMIT)

/* List all elements in the array */
DO K=1 TO LIMIT
SAY ARR.K
END
EXIT

FIBONACCI: PROCEDURE EXPOSE ARR.

/* Expose the array ARR so it is updated throughout the calls */
/* CURRENT is the current number being computed */

CURRENT = ARG(1)

/* If DATAYPE is NUM, it means we've already computed that number so we return it */

IF DATATYPE(ARR.CURRENT) = "NUM" THEN RETURN ARR.CURRENT

/* Else, we compute the fibonacci number recursively */

IF CURRENT = 1 | CURRENT = 2 THEN ,
ARR.CURRENT = 1
ELSE ,
ARR.CURRENT = FIBONACCI(CURRENT-2) + FIBONACCI(CURRENT-1)

RETURN ARR.CURRENT
Gilles
 
Posts: 16
Joined: Mon Sep 29, 2008 6:10 pm
Has thanked: 0 time
Been thanked: 0 time

Re: fibonacci series using rexx

Postby dick scherrer » Tue Sep 30, 2008 6:34 am

Hello Gilles and welcome to the forum,

Good to "see" you here :)

Thanks for your code ;)

Hopefully, you will find something useful here.

d
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: fibonacci series using rexx

Postby surendarRT » Fri Jun 25, 2010 8:23 pm

/*REXX*/
SAY "HOW MANY FIB U WANT"
PULL Q
L = Q - 4
SAY "0"
SAY "1"
SAY "1"
SAY "2"
W = 1
T = 2
DO I = 1 TO L
E= W + T
SAY E
W = T
T = E
END
EXIT
surendarRT
 
Posts: 1
Joined: Fri Jun 25, 2010 8:21 pm
Has thanked: 0 time
Been thanked: 0 time


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post