Deret Fibonacci

Bismillah…

Yuk, kita belajar membuat program fibonacci dengan java.. check it out!!

Algoritma Fibonannci

  1. inisialisasi a=0, b=1,i
  2. Inputkan jumlah bilangan yang akan ditampilkan, masukkan ke variable jml
  3. Tampilkan fib[0] dan fib[1] yaitu {1} dan {1}
  4. Proses looping

for i=0 to i<jml do
write(a)
a=a+b
b=a-b

01 /**
02  *
03  * @author Sheilla
04  */
05 import java.util.Scanner;
06 public class Fibonancci {
07     public static void main(String args[]){
08         int []data=null, fibo;
09         int i,a=0;
10         int b=1;
11         
12         Scanner input= new Scanner(System.in);
13         System.out.println("masukkan jumalah deret fibonannci");
14         int deret= input.nextInt();
15         
16        System.out.print(deret+" deret Fibonacci: " );
17         for (i=0;i<deret;i++){
18             System.out.print(a+" ");
19             a=a+b;
20             b=a-b;
21
22         }
23         
24     }
25 }

About Sheilla Rizkia Ferianty

Semangat!

Posted on 03/12/2011, in Java and tagged , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: