Thursday 9 January 2014

TUTORIAL C++ PROGRAM MATRIKS



#include<iostream>
using namespace std;
int main()
{
    int penjumlahan,pengurangan,perkalian,operasi;
    cout<<"\t===============================================================\n";
    cout<<" \t  PROGRAM PENJUMLAHAN,PENGURANGAN, DAN PERKALIAN MATRIK \n";
    cout<<"\t===============================================================\n";
    cout<<endl;
    cout<<" 1. OPERASI PENJUMLAHAN MATRIK \n";
    cout<<" 2. OPERASI PENGURANGAN MATRIK \n";
    cout<<" 3. OPERASI PERKALIAN MATRIK \n" ;
    cout<<" PILIH OPERASI MATRIK YANG DIINGINKAN : ";cin>>operasi;



    switch(operasi)
    {
        case 1:
            int baris_a,kolom_a,baris_b,kolom_b,baris_c,kolom_c,x,y;
            float matrik_a[15][15],matrik_b[15][15],matrik_c[15][15];
            cout<<"\t\t============================\n";
            cout<<" \t\t1.OPERASI PENJUMLAHAN MATRIK \n";
            cout<<"\t\t============================\n";
            cout<<endl;
            cout<<" MASUKAN JUMLAH BARIS MATRIK A : ";cin>>baris_a;
            cout<<" MASUKAN JUMLAH KOLOM MATRIK A : ";cin>>kolom_a;
            cout<<" MASUKAN JUMLAH BARIS MATRIK B : ";cin>>baris_b;
            cout<<" MASUKAN JUMLAH KOLOM MATRIK B : ";cin>>kolom_b;
            cout<<"================================================\n";
            cout<<endl;
            // input matrik A
            cout<<" MASUKAN NILAI MATRIK A : \n";
            cout<<"==========================\n";
            for(x=0;x<baris_a;x++)
            {
                for(y=0;y<kolom_a;y++)
                {
                    cout<<" MASUKAN NILAI MATRIK : ";
                    cin>>matrik_a [x][y];
                }
               
            }
            cout<<endl;
           
            // input matrik B
            cout<<" MASUKAN NILAI MATRIK B : \n";
            cout<<"==========================\n";
            for(x=0;x<baris_b;x++)
            {
                for(y=0;y<kolom_b;y++)
                {
                    cout<<" MASUKAN NILAI MATRIK : ";
                    cin>>matrik_b [x][y];
                }
            }
            cout<<endl;
           
            // cetak matrik A
            cout << "NILAI MATRIK A ADALAH : " << endl;
            for (x=0;x<baris_a;x++)
            {
                for (y=0;y<kolom_a;y++)
                   {
                        cout << matrik_a [x][y] << "   " ;
                }
                cout << endl;
            }
            cout << endl;
           
            //cetak matrik B
            cout<< "NILAI MATRIK B ADALAH : "<<endl;
            for(x=0;x<baris_b;x++)
            {
                for(y=0;y<kolom_b;y++)
                {
                    cout<<matrik_b[x][y]<<"   ";
                }
                cout<<endl;
            }
            cout<<endl;
           
            // cetak hasil matrik A + B
            cout<< "HASIL OPERASI MATRIK A + MATRIK B ADALAH : "<<endl;
            for(x=0;x<baris_a;x++)
            {
                for(y=0;y<kolom_b;y++)
                {
                    cout<<matrik_a[x][y]+matrik_b[x][y]<<"   ";
                }
                cout<<endl;
            }
            cout<<endl;
            break;
        case 2:
            cout<<"\t\t============================\n";
            cout<<" \t\t2.OPERASI PENGURANGAN MATRIK \n";
            cout<<"\t\t============================\n";
            cout<<endl;
            cout<<" MASUKAN JUMLAH BARIS MATRIK A : ";cin>>baris_a;
            cout<<" MASUKAN JUMLAH KOLOM MATRIK A : ";cin>>kolom_a;
            cout<<" MASUKAN JUMLAH BARIS MATRIK B : ";cin>>baris_b;
            cout<<" MASUKAN JUMLAH KOLOM MATRIK B : ";cin>>kolom_b;
            cout<<"================================================\n";
            cout<<endl;
            // input matrik A
            cout<<" MASUKAN NILAI MATRIK A : \n";
            cout<<"==========================\n";
            for(x=0;x<baris_a;x++)
            {
                for(y=0;y<kolom_a;y++)
                {
                    cout<<" MASUKAN NILAI MATRIK : ";
                    cin>>matrik_a [x][y];
                }
               
            }
            cout<<endl;
           
            // input matrik B
            cout<<" MASUKAN NILAI MATRIK B : \n";
            cout<<"==========================\n";
            for(x=0;x<baris_b;x++)
            {
                for(y=0;y<kolom_b;y++)
                {
                    cout<<" MASUKAN NILAI MATRIK : ";
                    cin>>matrik_b [x][y];
                }
            }
            cout<<endl;
           
            // cetak matrik A
            cout << "NILAI MATRIK A ADALAH : " << endl;
            for (x=0;x<baris_a;x++)
            {
                for (y=0;y<kolom_a;y++)
                   {
                        cout << matrik_a [x][y] << " " ;
                }
                cout << endl;
            }
            cout << endl;
           
            //cetak matrik B
            cout<< "NILAI MATRIK B ADALAH : "<<endl;
            for(x=0;x<baris_b;x++)
            {
                for(y=0;y<kolom_b;y++)
                {
                    cout<<matrik_b[x][y]<<" ";
                }
                cout<<endl;
            }
            cout<<endl;
           
            // cetak hasil matrik A - B
            cout<< "HASIL OPERASI MATRIK A - MATRIK B ADALAH : "<<endl;
            for(x=0;x<baris_a;x++)
            {
                for(y=0;y<kolom_b;y++)
                {
                    cout<<matrik_a[x][y]- matrik_b[x][y]<<" ";
                }
                cout<<endl;
            }
            cout<<endl;
            break;
        case 3:
            cout<<"\t\t============================\n";
            cout<<" \t\t3.OPERASI PERKALIAN MATRIK \n";
            cout<<"\t\t============================\n";
            cout<<endl;
            cout<<" MASUKAN JUMLAH BARIS MATRIK A : ";cin>>baris_a;
            cout<<" MASUKAN JUMLAH KOLOM MATRIK A : ";cin>>kolom_a;
            cout<<" MASUKAN JUMLAH BARIS MATRIK B : ";cin>>baris_b;
            cout<<" MASUKAN JUMLAH KOLOM MATRIK B : ";cin>>kolom_b;
            cout<<"================================================\n";
            cout<<endl;
            // input matrik A
            cout<<" MASUKAN NILAI MATRIK A : \n";
            cout<<"==========================\n";
            for(x=0;x<baris_a;x++)
            {
                for(y=0;y<kolom_a;y++)
                {
                    cout<<" MASUKAN NILAI MATRIK : ";
                    cin>>matrik_a [x][y];
                }
               
            }
            cout<<endl;
           
            // input matrik B
            cout<<" MASUKAN NILAI MATRIK B : \n";
            cout<<"==========================\n";
            for(x=0;x<baris_b;x++)
            {
                for(y=0;y<kolom_b;y++)
                {
                    cout<<" MASUKAN NILAI MATRIK : ";
                    cin>>matrik_b [x][y];
                }
            }
            cout<<endl;
           
            // cetak matrik A
            cout << "NILAI MATRIK A ADALAH : " << endl;
            for (x=0;x<baris_a;x++)
            {
                for (y=0;y<kolom_a;y++)
                   {
                        cout << matrik_a [x][y] << "   " ;
                }
                cout << endl;
            }
            cout << endl;
           
            //cetak matrik B
            cout<< "NILAI MATRIK B ADALAH : "<<endl;
            for(x=0;x<baris_b;x++)
            {
                for(y=0;y<kolom_b;y++)
                {
                    cout<<matrik_b[x][y]<<"   ";
                }
                cout<<endl;
            }
            cout<<endl;
           
            // cetak hasil matrik A * B
            cout<< "HASIL OPERASI MATRIK A * MATRIK B ADALAH : "<<endl;
            for(x=0;x<baris_a;x++)
            {
                for(y=0;y<kolom_b;y++)
                {
                    cout<<matrik_a[x][y]* matrik_b[x][y]<<"   ";
                }
                cout<<endl;
            }
            cout<<endl;
            break;
        default:
            cout<<"=============================\n";
            cout<<" PILIHAN ANDA SALAH \n";
            cout<<endl;
            cout<<" PILIH 1-3 \n";
            cout<<endl;
            cout<<" TERIMAKASIH \n";
            cout<<"==============================";
           
    }
   
   
   
}

No comments:

Post a Comment