Page 1 of 1

fibonacci series using rexx

PostPosted: Fri Aug 01, 2008 5:36 pm
by supriya saraswat
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.

Re: fibonacci series using rexx

PostPosted: Fri Aug 01, 2008 6:05 pm
by shivendu
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

Re: fibonacci series using rexx

PostPosted: Mon Aug 04, 2008 11:47 am
by supriya saraswat
no ...
i just want a program for fibonacci series .simple.

Re: fibonacci series using rexx

PostPosted: Mon Aug 04, 2008 12:05 pm
by dick scherrer
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.

Re: fibonacci series using rexx

PostPosted: Tue Aug 05, 2008 11:48 am
by supriya saraswat
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

Re: fibonacci series using rexx

PostPosted: Fri Aug 29, 2008 1:02 pm
by krsk0101
Hello,
Is that code working? Please let me know.....

Re: fibonacci series using rexx

PostPosted: Mon Sep 29, 2008 6:38 pm
by Gilles
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

Re: fibonacci series using rexx

PostPosted: Tue Sep 30, 2008 6:34 am
by dick scherrer
Hello Gilles and welcome to the forum,

Good to "see" you here :)

Thanks for your code ;)

Hopefully, you will find something useful here.

d

Re: fibonacci series using rexx

PostPosted: Fri Jun 25, 2010 8:23 pm
by surendarRT
/*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