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 ();
}
9:13:00 PM
|
Label:
kampus,
materi belajar
|
- Gunadarma University
- Baak Online
- StaffSite Universitas Gunadarma
- StudentSite Gunadarma
- Virtual Class Universitas Gunadarma
- LePKom Gunadarma
- iLab Gunadarma
- Laboratorium Fisika Gunadarma
- Lab Manajemen Lanjut Gunadarma
- UG Conference
- Perpustakaan Universitas Gunadarma
- FIKTI Universitas Gunadarma
- UG Knowledge Based portal
0 komentar:
Posting Komentar