Skip to main content

2D Array in C++

 


#include <bits/stdc++.h>
using namespace std;

class matrix
{

    int a[10][10];
    int b[10][10];

public:
    // void setdata(int x[], int y[]){
    //     a=x;
    //     b=y;
    // }

    void getdata(int m, int n)
    {
        int i, j;
        cout << "Enter the 1st's Elements: ";
        for (i = 0; i < m; i++)
        {
            for (j = 0; j < n; j++)
            {
                cin >> a[i][j];
            }
        }

         cout << "Enter the 2nd's Elements: ";
        for (i = 0; i < m; i++)
        {
            for (j = 0; j < n; j++)
            {
                cin >> b[i][j];
            }
        }
       
        cout << "\tMatrix\n";
        for (i = 0; i < m; i++)
        {
            cout << "\n";
            for (j = 0; j < n; j++)
            {
                cout << "\t" << a[i][j]+b[i][j];
            }
        }
    }
};

int main()
{
    matrix c;
    int x, y;
    cout << "How many Row u want: ";
    cin >> x;
    cout << "\nHow many Column u want: ";
    cin >> y;

    c.getdata(x, y);
   

    return 0;
}
   

Comments