Difference between revisions of "Fibonacci sequence"

From CompSciWiki
Jump to: navigation, search
Line 10: Line 10:
 
"The 10th number of the fibonacci sequence is X". (where X should be the 10th number.)<br/>  
 
"The 10th number of the fibonacci sequence is X". (where X should be the 10th number.)<br/>  
 
<br/>
 
<br/>
Note that the fibonacci sequence Xn = Xn-1 + Xn-2 <br/>
+
Note that the fibonacci sequence is F(n) = F(n-1) + F(n-2) for n > 1, F(1) = 1, F(0) = 1.<br/>
where: <br/>
+
Example: F(5) = 1, 1, 2, 3, 5
*Xn is the term number "n", in this case n will be 10,<br/>
+
*Xn-1 is the previous term (n-1) which will be 9, and<br/>
+
*Xn-2 is the term before that (n-2) which will be 8.<br/>
+
 
+
 
+
 
+
  
 
|SolutionCode=public class Fibonacci
 
|SolutionCode=public class Fibonacci

Revision as of 12:40, 1 April 2010

Back to the Program-A-Day homepage

Problem

Write a complete Java program Fibonacci that:

  • prompts 10 fibonacci numbers
  • prints out the 10th fibonacci number, using System.out.println


Your output should look something like
"The 10th number of the fibonacci sequence is X". (where X should be the 10th number.)

Note that the fibonacci sequence is F(n) = F(n-1) + F(n-2) for n > 1, F(1) = 1, F(0) = 1.
Example: F(5) = 1, 1, 2, 3, 5

 

...by students

float
Taken from http://www.flickr.com/photos/daniello/565304023/

An image or By Students section

Solution

The solution...

Code

Solution Code

Back to the Program-A-Day homepage