C++ Program to take marks from user as an input and display all the marks on the console screen using two dimensional arrays.


#include<iostream>

using namespace std;

int main()

{
//initializing 2D array (first for row and second for column)
int marks[4][5];
//using for loop because we know how many times we want to do task.
for(int row=0;row<4;row++)
//outer loop execute once while inner loop executes completely.
//in outer loop,when condition becomes true then inner loop starts executing completely.After it,inner loop starts to do increment i.e.row++. 
     {

for(int column=0;column<5;column++)

    {
    cout<<"Enter the value of ["<<row<<"]["<<column<<"] :";

    cin>>marks[row][column];

    }

    }
//here I repeat the above process to display marks but in this case i do not take input (as marks) from user because i am interested to display them so i simply cout the marks by using same inner and outer loops.
for(int row=0;row<4;row++)

     {

for(int column=0;column<5;column++)

    {
     cout<<marks[row][column]<<" ";
    }

    cout<<endl;
    }

return 0;
}


Note: You can ask any question relevant to it in comment section.

Comments

Popular Posts