Friday, 8 November 2013

Penjumlahan Matrix C++


#include
#include

using namespace std;


int main()
{
    int a[10][10];
    int b[10][10];
    int bara, barb, kola, kolb, i, j;

    cout << "Masukkan ukuran matrix-1 (A X B)";
    cout << "\nA = ";
    cin >> bara;
    cout << "B = ";
    cin >> kola;
    cout << "Masukkan ukuran matrix-2 (A X B)";
    cout << "\nA = ";
    cin >> barb;
    cout << "B = ";
    cin >> kolb;

    if (bara == barb && kola == kolb){
        cout << "Data matrix-1";
        cout << "\n";
        for (i = 1; i <= bara; i++){
            for (j = 1; j <= kola; j++){
                cout << "Masukkan data matrix-1 [" << i << "," << j << "] : ";
                cin >> a[i][j];
            }
        }
        cout << "\nData matrix-2";
        cout << "\n";
        for (i = 1; i <= barb; i++){
            for (j = 1; j <= kolb; j++){
                cout << "Masukkan data matrix-2 [" << i << "," << j << "] : ";
                cin >> b[i][j];
            }
        }
        cout << "\nHasil penjumlahan kedua matrix diatas adalah ";
        for (i = 1; i <= bara; i++){
            cout << "\n";
            for (j = 1; j <= kolb; j++){
                cout << a[i][j] + b[i][j] << " ";
            }
        }
    }
    else{
        cout << "Matrix tidak kompatible !!!";
    }
    getch();
    return 0;
}
Previous Post
Next Post

0 komentar: