pemrograman penjumlahan matriks

Document Sample

```					I MADE KERTAYASA
0808205002
PROGRAM PENJUMLAHAN MATRIKS

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

#define Nmaks 25

typedef int matriks[Nmaks][Nmaks];
void main()
{
int colA,colB,rowA,rowB,i,j;
matriks A,B,C;

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

clrscr();
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 Penjumlahan Matriks
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colA;j++)
{
C[i][j] = A[i][j] + B[i][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,13);
cout<<"B = ";
for(i=1;i<=rowB;i++)
{
for(j=1;j<=colB;j++)
{
gotoxy(2+4*j,10+2*i);
cout<<B[i][j];
}
}

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

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

gotoxy(32,20);
cout<<" = ";
for(i=1;i<=rowA;i++)
{
for(j=1;j<=colA;j++)
{
gotoxy(33+4*j,17+2*i);
cout<<C[i][j];
}
}

getch();
clrscr();
cout<<"== PROGRAM SELESAI =="<<endl<<endl;
cout<<"Mau Melakukan Perhitungan Lagi?? [Y/T]"; cin>>answer;
}