Selasa, 28 Juni 2011

perkalian matriks ordo 2x2

JAN29

import jeliot.io.*;

public class MyClass {
public static void main() {
// Your algorithm goes here.
int a [][];
int b [][];
int c [][];
int baris;
int kolom;
a= new int[2][2];

for (baris=0;baris<=1;baris ++){
for (kolom=0;kolom<=1;kolom ++){
System.out.print("input matriks("+ baris +","+ kolom +"):");
a[baris][kolom] = Input.readInt();
}
}

b= new int[2][2];
for (baris=0;baris<=1;baris ++){
for (kolom=0;kolom<=1;kolom ++){
System.out.print("input matriks("+ baris +","+ kolom +"):");
b[baris][kolom] = Input.readInt();
}
}

c= new int[2][2];
c[0][0]=a[0][0]*b[0][0]+a[0][1]*b[1][0] ;
c[0][1]=a[0][1]*b[0][0]+a[1][1]*b[0][1] ;
c[1][0]=a[0][0]*b[1][0]+a[1][0]*b[1][1] ;
c[1][1]=a[0][1]*b[1][0]+a[1][1]*b[1][1] ;
int x;
int z;

for(x=0;x<=1;x++){
for(z=0;z<=1;z++){
System.out.print(c[x][z]+"  ");
}
System.out.println();
}
}
}

0 komentar:

Posting Komentar