Source code program Perkalian Matriks pada C++

seperti ini nih coding nya :)


//program perkalian matriks
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
void main ()
{
int a[3][3], b[3][3], c[3][3], i, j, k;
clrscr ();
//masukkan matriks pertama
cout << "Silahkan input Matriks Pertama: \n";
cout << "------------------------------- \n";
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
cout << "Elemen (" << (i+1) << "," << (j+1) << ") :";
cin >> a[i][j];
}
}
//cetak matriks pertama
cout << "\nMatriks Pertama: \n";
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
cout << setw(4) << a[i][j];
}
cout << endl;
}
getch ();
clrscr ();
//masukkan matriks kedua
cout << "Silahkan input matriks Kedua: \n";
cout << "----------------------------- \n";
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
cout << "Elemen (" << (i+1) << "," << (j+1) << ") :";
cin >> b[i][j];
}
}
//cetak matriks kedua
cout << "\nMatriks Kedua: \n";
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
cout << setw(4) << b[i][j];
}
cout << endl;
}
cout << "\n \n" << "HASILNYA?? (klik enter)";
getch ();
clrscr ();
//Operasi Perkalian
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
c[i][j] = 0;
for (k=0; k<3; k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
//cetak matriks input
cout << "PERKALIAN MATRIKS \n";
cout << "--------- ------- \n";
cout << "\nMatriks Pertama: " << setw(20) << "Matriks Kedua: \n";
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
cout << setw(4) << a[i][j];
}
cout << setw(10) << " ";
for (k=0; k<3; k++)
{
cout << setw(4) << b[i][k];
}
cout << endl;
}
cout << endl << endl;
//Menampilkan hasil
cout << setw(25) << "Matrik Hasil: \n";
for (i=0; i<3; i++)
{
cout << setw(10) << " ";
for (j=0; j<3; j++)
{
cout << setw(4) << c[i][j];
}
cout << endl;
}
cout << endl;
getch ();
}

0 komentar:

Posting Komentar

indrinovii. Diberdayakan oleh Blogger.

news Studentsite

kamu pengunjung ke-

follow blog aku yaa :)

AUXILIARY 2010

AUXILIARY 2010

Full TAW ISE

Full TAW ISE
www.flickr.com
This is a Flickr badge showing public photos and videos from iin.indrinoviyanti. Make your own badge here.