Anda di halaman 1dari 3

//menulis bentuk matriks

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
main()
{
int a1, b1, a2, b2, x, y, z;
int mat1[20][20];
int mat2[20][20];
int mat3[20][20];
char lagi;
awal:
clrscr();
gotoxy(15,2);cout<<"=============================================";
gotoxy(15,3);cout<<"||
Program Perkalian 2 buah Matriks
||";
gotoxy(15,4);cout<<"=============================================";
cout<<endl<<endl<<"Inputkan baris matriks 1: ";
cin>>a1;
cout<<"Inputkan kolom matriks 1: ";
cin>>b1;
cout<<"Inputkan baris matriks 2: ";
cin>>a2;
cout<<"Inputkan kolom matriks 2: ";
cin>>b2;
if(b1!=a2)
{
cout<<endl;
cout<<"kolom matriks pertama tak sama dengan baris matriks kedua!"<<endl
;
cout<<"Matriks tak dapat dioperasikan dalam bentuk perkalian"<<endl;
cout<<"Silahkan input ulang . . .";
getch();
goto awal;
}
clrscr();
cout<<endl<<"ordo matriks pertama adalah "<<a1<<" x "<<b1<<endl;
cout<<"silahkan isi matriks : "<<endl;
for(x=1;x<=a1;x++)
{
for(y=1;y<=b1;y++)
{
cout<<"[ "<<x<<" , "<<y<<" ] : ";
cin>>mat1[x][y];
}
}
clrscr();
cout<<endl<<"ordo matriks kedua adalah "<<a2<<" x "<<b2<<endl;
cout<<"silahkan isi matriks : "<<endl;
for(x=1;x<=a2;x++)
{
for(y=1;y<=b2;y++)
{
cout<<"[ "<<x<<" , "<<y<<" ] : ";

} cout<<" |". } cout<<endl<<"Mau menghitung lagi (Y/N) ?? ". cout<<endl. } } } cout<<endl<<"Hasil perkalian Matriks : "<<endl. for(y=1.y<=b1.z<=a2. } getch(). for(y=1.x++) { for(y=1. } cout<<endl<<"Bentuk Matriks 2 : "<<endl.y++) { cout<<mat3[x][y]<<setw(5).x++) { cout<<"| ".y++) { cout<<mat1[x][y]<<setw(4). cout<<endl. cout<<endl. if(lagi=='Y'||lagi=='y') goto awal. cout<<"Bentuk Matriks 1 : "<<endl.y++) { cout<<mat2[x][y]<<setw(4). } } clrscr().cin>>mat2[x][y]. for(y=1.x++) { cout<<"| ".y++) { mat3[x][y]=0. for(x=1.x<=a1. .x++) { cout<<"| ".z++) { mat3[x][y]=mat3[x][y]+(mat1[x][z]*mat2[z][y]).y<=b2. for(x=1.y<=b2.x<=a2.y<=b2.x<=a1. } cout<<" |". } cout<<" |".x<=a1. for(z=1. for(x=1. for(x=1. cin>>lagi.

} .