C++ contoh program penjumlahan matriks
berikut adalah contoh program penjumlahan matriks tentunya dengan menggunakan konsep array dua dimensi. bagi teman-teman yang ingin mempelajarinya dibawah ini adalah source kode program penjumlahan matriks :
#include <iostream.h>
#include <conio.h>
// penjumlahan matriks dubraw735.blogspot.com
void main()
{
int matrix[20][30], matrix2[2][3],jumlah[2][3];
int i, j;
cout<<"matrix A :";
cout<<endl;
for (i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
cout<<"masukkan nilai baris"<<i<<" kolom "<<j<<" : ";
cin>>matrix[i][j];
}
}
cout<<"\nMatrix B :\n";
for (i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
cout<<"masukkan nilai baris"<<i<<" kolom "<<j<<" : ";
cin>>matrix2[i][j];
}
}
//proses hitung
for (i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
jumlah[i][j]=matrix[i][j] + matrix2[i][j];
}
}
//output penjumlahan
cout<<endl;
//output jumlah
gotoxy(1,20);
cout<<"C = ";
for(i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(3+4*j,17+2*i);
cout<<matrix[i][j];
}
}
gotoxy(17,20);
cout<<" + ";
for(i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(18+4*j,17+2*i);
cout<<matrix2[i][j];
}
}
gotoxy(32,20);
cout<<" = ";
for(i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(33+4*j,17+2*i);
cout<<jumlah[i][j];
}
}
getch();
}
#include <iostream.h>
#include <conio.h>
// penjumlahan matriks dubraw735.blogspot.com
void main()
{
int matrix[20][30], matrix2[2][3],jumlah[2][3];
int i, j;
cout<<"matrix A :";
cout<<endl;
for (i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
cout<<"masukkan nilai baris"<<i<<" kolom "<<j<<" : ";
cin>>matrix[i][j];
}
}
cout<<"\nMatrix B :\n";
for (i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
cout<<"masukkan nilai baris"<<i<<" kolom "<<j<<" : ";
cin>>matrix2[i][j];
}
}
//proses hitung
for (i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
jumlah[i][j]=matrix[i][j] + matrix2[i][j];
}
}
//output penjumlahan
cout<<endl;
//output jumlah
gotoxy(1,20);
cout<<"C = ";
for(i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(3+4*j,17+2*i);
cout<<matrix[i][j];
}
}
gotoxy(17,20);
cout<<" + ";
for(i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(18+4*j,17+2*i);
cout<<matrix2[i][j];
}
}
gotoxy(32,20);
cout<<" = ";
for(i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
gotoxy(33+4*j,17+2*i);
cout<<jumlah[i][j];
}
}
getch();
}