S
sirusha
Please send me the code for Fabonicseries program in java
Fibonacci?sirusha said:Please send me the code for Fabonicseries program in java
Fibonacci series is:sirusha said:
Furious said:No problem.
fibonacci ( )
{
while(true)
{
System.out.println("I am a brainless twit.");
}
}
JanTheKing said:Sirusha,
I have written the following method to generate the first 100 numbers
in the fibonacci series. As Hiwa says, writing a Fibonacci program
should be fairly simple and request you to try your own approach.
John said:Come now. Everyone knows that the best way is:
static int fibonacci (int i) {
if (i <= 1)
return 1;
else
return fibonacci (i - 1) + fibonacci (i - 2);
}
Furious said:The OP didn't. Now you have deprived him/her of the pleasure of doing
his/her own homework.
John said:I'd like to see the teacher's face when he hands it in.
Mike said:To understand recusrion, you must first understand recursion
Martin said:Teachers throughout the whole world use this one to explain recursion![]()
Eric Sosman said:That has always puzzled me, because (as John Kennedy's code
above shows) the problem is poorly suited to a recursive solution.
The other common example is computing factorials, and recursion is
a poor choice of method for that one, too. Is it any wonder that
understanding of recursion proves difficult, when the teachers
offer such bad examples?
JanTheKing said:Hey Furious George,
Your mail was really hilarious. Thanks man.
I had knowingly coded the program like that - so that Sirusha puts some
original effort.
HINT to OP: Using a BigDecimal would solve the issue.
On the contrary, it is a beautifully simple piece of recursion. In a
proper
grown up language
(defun fibonacci (n)
(assert (integerp n) nil "N must be an integer")
(cond ((<= n 1) 1)
(t (+ (fibonacci (- n 1))
(fibonacci (- n 2))))))
You cannot come up with a non-recursive definition of the Fibonacci
series
which is simpler or more expressive than that. Computational efficiency?
Pah!
Karl said:And if you want to compute f(100) in less than 5 minutes, consider how you
might use a Map to improve efficiency.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.