Sabtu, 15 Oktober 2011

algoritma pemrograman

TUGAS
1. MEMBUAT DERET GANJIL
2. MEMBUAT DERET FABONANCI

Coding 1 :

public class Deretdona {
public static void main(String[] args) {
int n;
for(n=1;n<13;n+=2)
System.out.print(" "+ n);
}
}

( Output : 1 3 5 7 9 11 )


Coding 2 :

public class FibonanciDona {
public static int fibbon(int x){
if (x<=0 || x<=1){
return x;
}
else{
return fibbon(x-2)+fibbon(x-1);
}
}

public static void main(String[] args) {
int n=10;
for (int i=0;i System.out.print(fibbon(i)+" ");
}
}
}
Outpunya : 0 1 1 2 3 5 8 13 21 34

Tidak ada komentar:

Posting Komentar