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

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...