D4n9k3l's Blog
Just another WordPress.com weblog

Penjumlahan Matriks

Listing Program :

#include
#include

#define Nmaks 25

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

do
{
do
{
clrscr();
cout<<"MATRIKS A : "<<endl;
cout<>rowA;
cout<>colA;
cout<<endl<<endl;
cout<<"MATRIKS B : "<<endl;
cout<>rowB;
cout<>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<>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<>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<>answer;
}
while ((answer == ‘y’) || (answer == ‘Y’));
}

Tampilan Program :
1
2
3
4
5

Belum Ada Tanggapan to “Penjumlahan Matriks”

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: