# perkalian matriks

Document Sample

```					I MADE KERTAYASA
08205002
PROGRAM PERKALIAN MATRIKS

#include <iostream.h>
#include <conio.h>
#include <stdio.h>

#define ValueMax 25

typedef float matriks[ValueMax][ValueMax];

void main()
{

int colA,colB,rowA,rowB,i,j;
matriks A,B,C;

do
{
clrscr();
cout<<"MATRIKS A : "<<endl<<endl;
cout<<"Masukkan Jumlah Baris Matriks A : ";
cin>>rowA;
cout<<"Masukkan Jumlah Kolom Matriks A : ";
cin>>colA;
cout<<endl<<endl;
cout<<"MATRIKS B : "<<endl<<endl;
cout<<"Masukkan Jumlah Baris Matriks B : ";
cin>>rowB;
cout<<"Masukkan Jumlah Kolom Matriks B : ";
cin>>colB;
}
while (colA!=rowB);

clrscr();
cout<<"Masukkan Nilai Matriks A : "<<endl;
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colA;j++)
{
cout<<"A["<<i<<","<<j<<"] = ";
cin>>A[i][j];
}
}

cout<<endl<<endl;
cout<<"Masukkan Nilai Matriks B : "<<endl;
for(i=1;i<=rowB;i++)
{
for(j=1;j<=colB;j++)
{
cout<<"B["<<i<<","<<j<<"] = ";
cin>>B[i][j];
}
}

clrscr();
cout<<endl;
//Proses Perkalian Matriks
if(colA == 1)
{
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colB;j++)
{
C[i][j] = (A[i][1] * B[1][j]);
}
}
}

if(colA == 2)
{
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colB;j++)
{
C[i][j] = (A[i][1] * B[1][j] + A[i][2] * B[2][j]);
}
}
}
if(colA == 3)
{
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colB;j++)
{
C[i][j] = (A[i][1] * B[1][j] + A[i][2] * B[2][j] + A[i][3] * B[3][j]);
}
}
}

if(colA == 4)
{
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colB;j++)
{
C[i][j] = (A[i][1]*B[1][j] + A[i][2]*B[2][j] + A[i][3]*B[3][j] + A[i][4]*B[4][j]);
}
}
}

if(colA == 5)
{
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colB;j++)
{
C[i][j] = (A[i][1]*B[1][j] + A[i][2]*B[2][j] + A[i][3]*B[3][j] + A[i][4]*B[4][j] + A[i][5]*B[5][j]);
}
}
}

clrscr();
//Output Matriks A
gotoxy(1,5);
cout<<"A = ";
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colA;j++)
{
gotoxy(2+4*j,2+2*i);
cout<<A[i][j];
}
}

//Output Matriks B
gotoxy(1,17);
cout<<"B = ";
for(i=1;i<=rowB;i++)
{
for(j=1;j<=colB;j++)
{
gotoxy(2+4*j,14+2*i);
cout<<B[i][j];
}
}

//Output Matriks C
gotoxy(1,30);
cout<<"C = ";
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colA;j++)
{
gotoxy(3+4*j,27+2*i);
cout<<A[i][j];
}
}

gotoxy(25,30);
cout<<" X ";
for(i=1;i<=rowB;i++)
{
for(j=1;j<=colB;j++)
{
gotoxy(26+4*j,27+2*i);
cout<<B[i][j];
}
}

gotoxy(43,30);
cout<<" = ";
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colB;j++)
{
gotoxy(45+4*j,27+2*i);
cout<<C[i][j];
}
}

getch();
}

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 398 posted: 3/28/2011 language: Indonesian pages: 5
Description: tugas pemrograman tentang perkalian matriks
How are you planning on using Docstoc?