1
#include <iostream>
#include<fstream>

using namespace std;

int main() {
    int a = 1;

    if (a == 1) {
        int a[1][1];
        for (int i = 0; i <= 1; i++) {
            for (int j = 0; j <= 1; j++) {

                cin >> a[i][j];
            }
        }
        cout << endl;

        for (int k = 0; k <= 1; k++) {

            for (int l = 0; l <= 1; l++) {
                cout << a[k][l] << "   ";
            }
            cout << endl;
        }


    }

    return 0;
}

In this program if we enter input as : 1 2 3 4

it gives output : 1 3 3 1 it should give output as: 1 2 3 4 Please help, I am a beginner. I am coding in code blocks.

Umar Farooq
  • 418
  • 2
  • 14

1 Answers1

0

Try this

int main()
{
int arr[2][2]; // declares a 2x2 array

    cout << "Enter integers : " << endl;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> arr[i][j]; //inserts at the index i and j in the array
        }
    }

    cout << "Display array : " << endl;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            cout << arr[i][j] << endl; /*displays the value at 
            index i and j in the array*/
        }
    }
}
Zach_Mose
  • 357
  • 3
  • 7