Senin, 05 November 2012

PENJUMLAHAN MATRIKS A + B MENGGUNAKAN ARRAY C++


#include<iostream>
using namespace std;
int main () {
            int A[10][10];
            int B[10][10];
            int C[10][10];
            int a,b,c,d;
            cout<<endl;
            cout<<"Masukkan jumlah baris = ";
            cin>>a;
            cout<<endl;
            cout<<"Masukkan jumlah kolom = ";
            cin>>b;
            cout<<endl;
            cout<<"Matriks A["<<a<<"]["<<b<<"]"<<endl;
            cout<<endl;
            for(c=0;c<a;c++){
                        for(d=0;d<b;d++){
                                    cout<<"Masukkan nilai matriks A["<<c<<"]["<<d<<"]= ";
                                    cin>>A[c][d];
                                    cout<<endl;
                        }
            }
            cout<<"Jadi, Matriks A adalah"<<endl;
            for(c=0;c<a;c++){
                        for(d=0;d<b;d++){
                                    cout<<"   "<<A[c][d];
                        }
                        cout<<endl;
            }
            cout<<endl;
            cout<<"Matriks B["<<a<<"]["<<b<<"]"<<endl;
            cout<<endl;
            for(c=0;c<a;c++){
                        for(d=0;d<b;d++){
                                    cout<<"Masukkan nilai matriks B["<<c<<"]["<<d<<"]= ";
                                    cin>>B[c][d];
                                    cout<<endl;
                        }
            }
            cout<<"Jadi, Matriks B adalah"<<endl;
            for(c=0;c<a;c++){
                        for(d=0;d<b;d++){
                                    cout<<"   "<<B[c][d];
                        }
                        cout<<endl;
            }
            cout<<endl;
            cout<<"Hasil Penjumlahannya Adalah";
            cout<<endl;
            for(c=0;c<a;c++){
                        for(d=0;d<b;d++){
                                    C[c][d]=A[c][d]+B[c][d];
                                    cout<<"   "<<C[c][d];
                        }
                        cout<<endl;
            }
}

Tidak ada komentar:

Posting Komentar