vendredi 18 décembre 2020

How to fill a 2D through input and then read back as output in a C++. Here is the code which I wrote. I gives wrong output.I am a beginner

#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.

Aucun commentaire:

Enregistrer un commentaire