Program Deret Fibonaci Java

Listing

import java.util.Scanner;
public class fibonaci{
public static void main (String[]args){
int a = 0, b =1, c, total, batas;
Scanner input = new Scanner(System.in);

System.out.print("Masukkan Batas : ");
batas = input.nextInt();
System.out.print(a+"+"+b);
total = a + b;
for (int i=2;i<=batas;i++){
c = a + b;
a = b;
b = c;
if (i<batas){
System.out.print("+");
System.out.print(c);
total = c + total;
}else{
System.out.print("="+total);
}
}
}
}

Output


Komentar

Postingan populer dari blog ini

Fixed Point dan Floating Point pada ALU

Pengenalan Teknologi Game dan Artificial Intelligence pada Game || Pengantar Teknologi Game || Tugas I

Program Deret Geometri Java