Minggu, 24 Juni 2018

PROGRAM OPERASI PENGURANGAN DAN PERKALIAN MATRIX

TUGAS BAHASA PEMROGRAMAN
PERHITUNGAN OPERASI
PENGURANGAN DAN PERKALIAN MATRIX

Nama     : Ahmad Huzaeni
Nim       : 17.01.53.2009
Fakultas : Teknologi Informasi

Jurusan  : Teknik Informatika


FLOWCHART


KODE PROGRAM



import java.util.*;
import java.lang.Math;

public class matrixhitungan {
private static Scanner input_user = new Scanner(System.in);
public static void main(String[] args) {
int row, col, row_kali, col_kali;
int matrikA [][] = new int[2][2];
int matrikB [][] = new int[2][2];
int hasil_kurang [][] = new int[2][2];
int hasil_kali [][] = new int[2][2];
System.out.println("----- Pengurangan dan Perkalian Matriks -----");
System.out.println("\n- MATRIK A");
for(row = 0; row < matrikA.length; row++)
{
for(col = 0; col < matrikA.length; col++)
{
System.out.print("- Matrik A baris ke-"+(row+1)+" kolom ke-"+(col+1)+" : ");
matrikA[row][col] = input_user.nextInt();
}
}
System.out.println("\n- MATRIK B");
for(row = 0; row < matrikB.length; row++)
{
for(col = 0; col < matrikB.length; col++)
{
System.out.print("- Matrik B baris ke-"+(row+1)+" kolom ke-"+(col+1)+" : ");
matrikB[row][col] = input_user.nextInt();
}
}
System.out.println("\n* MATRIK A ");
for(row = 0; row < matrikA.length; row++)
{
for(col = 0; col < matrikA.length; col++)
{
System.out.print(matrikA[row][col]+" ");
}
System.out.println();
}

System.out.println("\n* MATRIK B ");
for(row = 0; row < matrikB.length; row++)
{
for(col = 0; col < matrikB.length; col++)
{
System.out.print(matrikB[row][col]+" ");
}
System.out.println();
}
System.out.println("\n* HASIL A - B ");
for(row = 0; row < hasil_kurang.length; row++)
{
for(col = 0; col < hasil_kurang.length; col++)
{
hasil_kurang[row][col] = matrikA[row][col] - matrikB[row][col];
System.out.print(hasil_kurang[row][col]+" ");
}
System.out.println();
}
System.out.println("\n* HASIL A * B ");
for(row_kali = 0; row_kali < hasil_kali.length; row_kali++)
{
for(row = 0; row < hasil_kali.length; row++)
{
for(col = 0; col < hasil_kali.length; col++)
{
hasil_kali[row_kali][row] += matrikA[row_kali][row] * matrikB[col][row];
}
System.out.print(hasil_kali[row_kali][row]+" ");
}
System.out.println();
}

}

}


HASIL UJI DENGAN JCREATOR



0 komentar:

Posting Komentar