Pages

Sunday, April 13, 2025

2D Array in C++

 #include <iostream>

using namespace std;
// 2d Array
int main() {
    int arr[3][4];
    int n = 3, m = 4;  // 3.4 = 12 values
   
        // input values
        for(int i=0; i<n; i++) {
            for(int j=0; j<m; j++) {
                cin >> arr[i][j];
            }
        }

        for(int i=0; i<n; i++) {
            for(int j=0; j<m; j++) {
                cout << arr[i][j] << " ";
            }
            cout << endl;
        }
   
    return 0;
}


OUTPUT-
1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12


No comments:

Post a Comment

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...