Upcoming SlideShare
×

# Tugas algoritma fibonacci

329 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
329
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
3
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Tugas algoritma fibonacci

1. 1. Listing Program Fibonacci /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package fibo; /** * * @author agatha */ public class Fibo { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int fibo[] = new int[15]; fibo[0] = 1; fibo[1] = 1; for (int i = 2; i < fibo.length; i++) { fibo[i] = fibo[i - 1] + fibo[i - 2]; } for (int i = 0; i < fibo.length; i++) { System.out.println(fibo[i]); } } }
2. 2. Bilangan Prima 1-100 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package bil_prima; /** * * @author agatha */ public class Bil_prima { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here char tanda[] = new char[101]; for (int i = 2; i <= 100; i++) { if (tanda[i] != '*') { System.out.print(i + " "); for (int j = i * 2; j <= 100; j += i) { tanda[j] = '*'; } } } } }
3. 3. Matrik 3x3 Penjumlahan /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package matrik3x3; import java.util.Scanner; /** * * @author agatha */ public class Matrik3x3 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); int i; int j; int matrikA[][] = new int[4][4]; int matrikB[][] = new int[4][4]; int jumlah[][] = new int[4][4]; for (i = 1; i < 4; i++) { for (j = 1; j < 4; j++) { System.out.print("Matrik A " + i + "." + j + "= "); matrikA[i][j] = input.nextInt(); } } System.out.println(); for (i = 1; i < 4; i++) { for (j = 1; j < 4; j++) { System.out.print("Matrik B " + i + "." + j + "= "); matrikB[i][j] = input.nextInt(); } } for (i = 1; i < 4; i++) { for (j = 1; j < 4; j++) { jumlah[i][j] = matrikA[i][j] + matrikB[i][j]; } } System.out.println("n Matrik A n"); for (i = 1; i < 4; i++) { for (j = 1; j < 4; j++) { System.out.print(" " + matrikA[i][j]); } System.out.println(); }
4. 4. System.out.println("nMatrik Bn"); for (i = 1; i < 4; i++) { for (j = 1; j < 4; j++) { System.out.print(" " + matrikB[i][j]); } System.out.println(); } System.out.println("nMatrik A + Matrik Bn"); for (i = 1; i < 4; i++) { for (j = 1; j < 4; j++) { System.out.print(" " + jumlah[i][j]); } System.out.println(); } } }
5. 5. Screenshot Program : 1. Fibonacci 2. Bilangan Prima 1-100 3. Matrik 3x3