Page cover

2-D Arrays

circle-exclamation
Numbers of Rows & Columns in 2d
int arr[][3] = { { 1, 2, 3 },
                 { 4, 5, 6 },
                 { 7, 8, 9 } };
    
    int total_Elements = sizeof(arr)/sizeof(int); // 36 / 4 = 9
    cout << "Total Number of elements are: " << total_Elements << endl; 

    int rows = sizeof(arr)/sizeof(arr[0]);  // 36 / 12 = 3

    int cols = sizeof(arr[0])/sizeof(int);  // 12 / 4 = 3
    
    cout << "No of Rows are: "   << rows << endl;
    cout << "No of Columns are: "<< cols << endl;
circle-check

Q1: Row-Wise Sum

Q2: Column-Wise Sum

Q5: Transpose of a Matrix

Q8: Addition of 2 Matrix

Q9: Multiplication of a matrix

Q10: Reverse 2d array

Last updated

Was this helpful?