Perkalian matriks

//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<<" ] : ";

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

} .

Sign up to vote on this title
UsefulNot useful