Halo kawan saya kali ini akan menjeaskan array 2 dimensi, berupa Algoritma dan juga programnya.
R ← 0
S ← 0
Total ← 0
Input Banyak Kolom ← A
Input Banyak Baris ← B
Array X[A][B+2]
Array Total[A+2][B]
X[A][B+1] ← 0
Total[A+1][B] ← 0
For R to A do
For S to B do
Masukkan Element Array ← X[R][S]
X[R][S+2] ←X[R][S]+X[R][S+1]
Total[R][S] ← X[R][S+2]
Total[R+2][S] ← Total[R][S]+Total[R+1][]
Total ← Total[A+2][B]
End for
End for
Write (Total)
Kode Program
package pkg2ez4opik;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int a,b,hasil=0;
int n,m;
System.out.print("Masukkan Banyak Kolom : ");
n=input.nextInt();
System.out.print("Masukkan Banyak Baris : ");
m=input.nextInt();
int x[][] = new int[n][m+2];
int total[][] = new int[n+2][m];
for (a=0;a<n;a++){
for (b=0;b<m;b++){
System.out.print("Masukkan Nilai Elemen Array : ");
x[a][b] = input.nextInt();
x[a][b+2] = x[a][b]+x[a][b+1];
total[a][b] = x[a][b+2];
total[R+2][S] = total[a][b]+total[a+1][b];
hasil=totalR+2][S];
}
System.out.println("#####################################");
}
System.out.println("Total Akumulasi Elemen Array : "+hasil);
}
}
TTERIMAKASIH SUDAH BBERKUNJUNG DI BLOK SAYA YANG SELALU SEPI DARI KAPAN TAHUN :v
No comments:
Post a Comment