Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <iomanip.h>
- using namespace std;
- int A[1000][1000],B[1000][1000],C[1000][1000],i,j,k, barisa, koloma, barisb, kolomb, barisc, kolomc, loop;
- void hitung();
- void matrika();
- void matrikb();
- void cek();
- void ulang();
- int main()
- {
- do
- {
- matrika();
- matrikb();
- ulang();
- }while (loop!=0);
- }
- void matrika()
- {
- cout<<"masukkan ordo matriks A :"<<endl;
- cout<<"jumlah baris : ";
- cin>>barisa;
- cout<<"jumlah kolom : ";
- cin>>koloma;
- //masukkan matrix A
- cout<<"Silahkan input matrik A : \n";
- for(i=0;i<barisa;i++)
- {
- for(j=0;j<koloma;j++)
- {
- cout<<"Elemen ke "<<(i+1)<<","<<(j+1)<<" : ";
- cin>>A[i][j];
- }
- }
- //cetak matrix A
- cout<<"\nMatrik A : \n";
- for(i=0;i<barisa;i++)
- {
- for(j=0;j<koloma;j++)
- {
- cout<<setw(4)<<A[i][j];
- }
- cout<<endl;
- }
- cout<<endl;
- }
- void matrikb()
- {
- barisb = koloma;
- //masukkan matriks B
- cout<<"masukkan ordo matriks B :"<<endl;
- cout<<"jumlah baris : "<<barisb;
- cout<<"\njumlah kolom : ";
- cin>>kolomb;
- cout<<"Silahkan input matrik B : \n";
- for(i=0;i<barisb;i++)
- {
- for(j=0;j<kolomb;j++)
- {
- cout<<"Elemen ke "<<(i+1)<<","<<(j+1)<<" : ";
- cin>>B[i][j];
- }
- }
- //cetak matrix B
- cout<<"\nMatrik B : \n";
- for(i=0;i<barisb;i++)
- {
- for(j=0;j<kolomb;j++)
- {
- cout<<setw(4)<<B[i][j];
- }
- cout<<endl;
- }
- }
- void hitung()
- {
- //Operasi Perkalian
- for (i=0;i<barisa;i++)
- {
- for (j=0;j<kolomb;j++)
- {
- C[i][j]=0;
- for (k=0;k<barisb;k++)
- {
- C[i][j]+= A[i][k]*B[k][j];
- }
- }
- }
- //Menampilkan hasil
- cout<<"\nMatrik C, Hasil : \n";
- for(i=0;i<barisa;i++)
- {
- for(j=0;j<kolomb;j++)
- {
- cout<<setw(4)<<C[i][j];
- }
- cout<<endl;
- }
- cout<<endl;
- getche();
- }
- void ulang()
- {
- int status, l;
- char pilih;
- do
- {
- cout<<"anda ingin memakai program ini lagi (y/n)?";
- cin>>pilih;
- switch (pilih)
- {
- case 'Y' : status=1; loop=1; l=0; break;
- case 'y' : status=1; loop=1; l=0; break;
- case 'N' : status=0; l=0; cout<<"exit"<<endl; getche(); exit(0); break;
- case 'n' : status=0; l=0; cout<<"exit"<<endl; getche(); exit(0); break;
- default : cout<<"ketik y untuk ulangi program, n untuk tutup program (tidak case sensitif)"<<endl;
- }
- }while(l!=0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement