[Java] Fibonacci Number Iterative
(Jul 11, 2008)
There is a program for Fibonacci Number normal and abnormal
/*Fibonacci Number
author http://www.programming-codes.co.cc*/
import java.util.*;
class Fibonacci{
public static void main(String args[]){
int a,b,c,input;
Scanner read = new Scanner(System.in);
a=0;
b=1;
c=1;
System.out.print(" *Program Fibonacci Normal dan Tak Normal*\n\n");
System.out.print("Masukkan banyaknya deret fibonacci= ");
input = read.nextInt();
System.out.print("Deret Fibonacci Normal= ");
for(int i=1;i<=input;i++){
System.out.print(c+" ");
c = a+b;
a = b;
b = c;
}
a=0;
b=1;
c=1;
System.out.print("\nDeret Fibonacci Tak Normal= ");
for(int i=1;i<=input;i++){
if (i % 2 == 0)
{
c=c*(-1);
}
else
{
c=c*1;
}
System.out.print(c+" ");
c = a+b;
a = b;
b = c;
}
System.out.println();
}
}
Download the code here
[ Read More ]
Posted in Label: Download, Java language, Source Code 0 komentar Diposting oleh Alexander Rahardjo