What's Here?
- Members: 95,475
- Replies: 379,759
- Topics: 56,732
- Snippets: 1,915
- Tutorials: 494
- Total Online: 968
- Members: 29
- Guests: 939
Who's Online?
|
Fibonacci sequence is a sequence of numbers defined by
f1 = 1
f2 = 1
fn = fn-1 + fn-2
First ten terms
1, 1, 2, 3, 5, 8, 13, 21, 34, 55
|
Submitted By: mukesh_ranjan18
|
|
Rating:

|
|
Views: 12,690 |
Language: Java
|
|
Last Modified: August 1, 2006 |
Snippet
package com.gpt;
import javax.swing.JOptionPane;
/*
This program computes Fibonacci numbers using a recursive
method.
*/
public class Fibonacci
{
public static void main (String[] args )
{
for (int i = 1; i <= n; i++)
{
int f = fib(i);
System. out. println("fib(" + i + ") = " + f );
}
}
/**
Computes a Fibonacci number.
@param n an integer
@return the nth Fibonacci number
*/
public static int fib(int n)
{
if (n <= 2)
return 1;
else
return fib(n - 1) + fib(n - 2);
}
}
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|