Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <cstdlib>
- using namespace std;
- void jumlah(){
- int i,j,x,y;
- cout<< "Masukkan baris matriks A: ";
- cin >>i;
- cout<< "Masukkan kolom matriks A: ";
- cin >>j; cout<<endl;
- int A[i][j];
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< "A[" << x << "][" << y << "]: ";
- cin>>A[x][y];
- }
- } cout<<endl;
- cout<< "Matriks A= " <<endl;
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< A[x][y] << " ";
- }
- cout<<endl;
- }
- cout<< "\nMasukkan baris matriks B: ";
- cin >>i;
- cout<< "Masukkan kolom matriks B: ";
- cin >>j; cout<<endl;
- int B[i][j];
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< "B[" << x << "][" << y << "]: ";
- cin>>B[x][y];
- }
- } cout<<endl;
- cout<< "Matriks B= " <<endl;
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< B[x][y] << " ";
- }
- cout<<endl;
- }
- system("pause");
- system("CLS");
- cout<< "\nMatriks A + Matriks B= " <<endl;
- int C[i][j];
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- C[x][y] = A[x][y] + B[x][y];
- cout<< C[x][y] << " ";
- }
- cout<<endl;
- }
- }
- void kurang(){
- int i,j,x,y;
- cout<< "Masukkan baris matriks A: ";
- cin >>i;
- cout<< "Masukkan kolom matriks A: ";
- cin >>j; cout<<endl;
- int A[i][j];
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< "A[" << x << "][" << y << "]: ";
- cin>>A[x][y];
- }
- } cout<<endl;
- cout<< "Matriks A= " <<endl;
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< A[x][y] << " ";
- }
- cout<<endl;
- }
- cout<< "\nMasukkan baris matriks B: ";
- cin >>i;
- cout<< "Masukkan kolom matriks B: ";
- cin >>j; cout<<endl;
- int B[i][j];
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< "B[" << x << "][" << y << "]: ";
- cin>>B[x][y];
- }
- } cout<<endl;
- cout<< "Matriks B= " <<endl;
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< B[x][y] << " ";
- }
- cout<<endl;
- }
- system("pause");
- system("CLS");
- cout<< "\nMatriks A - Matriks B= " <<endl;
- int C[i][j];
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- C[x][y] = A[x][y] - B[x][y];
- cout<< C[x][y] << " ";
- }
- cout<<endl;
- }
- }
- void kali(){
- int i,j,k,temp;
- int x,y,z;
- cout<< "Masukkan kolom matriks A: ";
- cin >>i;
- cout<< "Masukkan baris matriks A: ";
- cin >>j; cout<<endl;
- int A[i][j];
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< "A[" << x << "][" << y << "]: ";
- cin>>A[x][y];
- }
- } cout<<endl;
- cout<< "Matriks A= " <<endl;
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- cout<< A[x][y] << " ";
- }
- cout<<endl;
- }
- cout<< "\nMasukkan kolom matriks B: ";
- cin >>j;
- cout<< "Masukkan baris matriks B: ";
- cin >>k; cout<<endl;
- int B[j][k];
- for(y=0; y<j; y++){
- for(z=0; z<k; z++){
- cout<< "B[" << y << "][" << z << "]: ";
- cin>>B[y][z];
- }
- } cout<<endl;
- cout<< "Matriks B= " <<endl;
- for(y=0; y<j; y++){
- for(z=0; z<k; z++){
- cout<< B[y][z] << " ";
- }
- cout<<endl;
- }
- system("pause");
- system("CLS");
- int C[i][k];
- cout<< "Matriks A x Matriks B= " <<endl;
- for(x=0; x<i; x++){
- for(y=0; y<j; y++){
- C[x][y] = 0;
- for(z=0; z<k; z++){
- temp = A[x][z]*B[z][y];
- C[x][y] += temp;
- }
- }
- cout<<endl;
- }
- cout<< "Matriks C= " <<endl;
- for(y=0; y<j; y++){
- for(z=0; z<k; z++){
- cout<< C[y][z] << " ";
- }
- cout<<endl;
- }
- }
- int main()
- {
- int pilihan;
- menu:
- cout<< "\t\t\t#==============================#" <<endl;
- cout<< "\t\t\t#******** MENU MATRIKS ********#" <<endl;
- cout<< "\t\t\t#==============================#" <<endl;
- cout<< "\t\t\t# 1. PENJUMLAHAN #" <<endl;
- cout<< "\t\t\t# 2. PENGURANGAN #" <<endl;
- cout<< "\t\t\t# 3. PERKALIAN #" <<endl;
- cout<< "\t\t\t# 4. KELUAR #" <<endl;
- cout<< "\t\t\t#==============================#" <<endl;
- cout<< "\t\t\t Masukkan pilihan: ";
- cin>>pilihan;
- system("CLS");
- switch(pilihan){
- case 1: jumlah(); break;
- case 2: kurang(); break;
- case 3: kali(); break;
- case 4: exit(0);
- default:
- cout<<"Kode yang anda masukkan salah :(";
- }
- system("pause");
- system("CLS");
- goto menu;
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement