What's Here?
- Members: 300,322
- Replies: 825,548
- Topics: 137,368
- Snippets: 4,417
- Tutorials: 1,147
- Total Online: 2,012
- Members: 121
- Guests: 1,891
|
Outputs the fibonacci sequence using arrays very easy to change and alter to output more or less fibonacci numbers, can also be output to a txt file.
|
Submitted By: pink_floyd
|
|
Rating:

|
|
Views: 20,728 |
Language: Java
|
|
Last Modified: August 14, 2006 |
Snippet
//Programmed By: pink_floyd
//Date 08/08/06
//Fibonacci Sequence
import java.io.*;
public class FIBONACCI
{
{
int[] f = new int[46]; //creates array length of 46
f[0] = 1; //first item in array (computer starts counting at 0 not 1)
f[1] = 1; //second item in array
int x; //declares x of type int (integer)
System. out. print(f [0] + "\n" + f [1] + "\n"); //outputs the first 2 elements in array f
for(x=2; x<=45; x++) //notice 'x<=45' not 46 has to be 45 if any higher cannot handle array
{
f[x] = f[x-1] + f[x-2];//calculates next element in array
System. out. println(f [x ]); //output next elements in array 2-45
}
}
}
Copy & Paste
|
|
|
|