Hi everyone.
So in this lesson we are going to learn what our two dimensional at is so consider for example you want
to implement board a game.
So let us consider that you want to implement our tic tac toe game so intact tactile we have a basically
two dimensional Larry and basically direct to you rules and three columns so this matrix has a dimension
of three cores three now with the current knowledge that we have.
How can we store detectable.
So basically the first option is with the use of three one dimensional Eddie.
So I will create three areas.
So even if you do and 80
so even will correspond to the first rule you two is going to correspond for the second row and A3 is
for the third row of detectors.
So this even restore the data president in the first row you to restore the data president in the second
row and a previous order data present in the third row.
So for example if you do something here if are going to store something here.
Then that data will be stored at this point.
If you want to store something at this location.
So you have to go to edit 3 and add zero index.
You will solve the data.
So this is the first option but this option is not very good.
Why this is not very good.
Because suppose you want to implement a chess game so inches you have it cross it.
So basically you have to take it one dimensional Eddie.
So even do it.
So I have to take it one be Eddie one dimensional Eddie.
So this first option is not a very good option.
Now the second option for implementing tic tac toe.
What can I do.
So in total I have nine cents.
So what I will do I will create a one degree.
And in this one day I will basically have.
So this one day it will be of size nine.
So the first and next will be zero.
And the last index is going to be eight now for example if you want to insert something at this location.
So if will do the indexing so 0 1 Do you remember the indexing always starts from zero.
So this is 0 1 2.
Now what I want to do I want to store something at this location.
So it's the rule number is two.
And it indexes one.
So I want to store something at this location to code 11 and what this location will be in this area.
So basically if you count so one two three four five six seven and eight.
So its location will be seven so you will store whatever you are going to store at this location that
will be stored at the nexus 7 corresponding to this one that mission at.
So this is our second option or it off implementing the tic tac toe again.
So the problem with this approach is basically you have to calculate.
You have to do some calculation to find out the index in the 80 but the third option of implementing
tic tac toe is with the help of two damaged letters.
So now let's see what are two damage salaries.
So as the name suggests there will be two dimensions just like three across three.
So basically there are two dimensions in chess.
We have two dimensions eight closet.
So now let's see how we will create our to damage Hillary.
So for example if you want to create an idea what you will write you will write it deja if you want
to create a different teacher then the name of the array and then let's say I want lent five.
So what will happen you will get an array the first index is going to be zero and the last index is
going to be.
Now if you want to create a tool that that it would do well right.
So I want to create the Mitchell that often do just so I will give the data type then the name of the
area.
So I want to be led to the name of that is B.
Now you have to give two things.
So here the ad is a one dimensional.
So you just have to give the land.
But the two that Mitchell at is.
So there are two damage and first I have rules and I have columns.
So what I will do I will write like this one box and second box.
So this first box will contain how many tools and the second box will contain how many columns.
So for example if I give 3Com a Ford 3 and 4.
And so what really we might do these metrics.
So I will have three rows and I will have four columns.
So this is the number of rows so Tito's so these are the tables and I want four columns.
So this is the first column.
The second column third and fourth column and we know the indexing in the IRS starts from zero.
So similarly the indexing will start some 0 so the 0 1 2 3 I have four columns and 0 1 2.
So I have three rules.
So what is the last index last year nixes basically two commentary.
What is the first index so Foster indexes is a zero comma zero.
So now let's say if you want to take input.
So how can you take input.
So in every if you've undertaken.
So what we have to do.
I will write how many elements you want to insert.
Then I will take the number of elements and then basically you have to use a for loop starting from
zero and I list in it.
And I plus plus.
And then you will do something like this.
Each if I use the name of the area.
So for taking the input from the user we have to do this thing.
Now let's see how we can take input in beauty metrics into their machinery.
So let's see.
So there are two ways of taking input.
So what is the first option.
So the first option is basically take input always and the second option is basically take input column
wise.
So what is the meaning of railways.
So railways is very common and we will use this only so railways means taken but for the zero total
then take input for the first row then they can put for the second to first of all I have to do.
I will take how many rules and how many columns.
So for these two.
The first step is going to be same you will create a truly matrix.
So let's say number of rules are handed number of columns that are also a hundred then you will take
two variables four rows and columns.
So let's call them a man and then you will take how many rows and it will take how many columns.
So here M signifies rules and is basically the number of columns.
So the first step is going to be very same.
Just like we used to take and hit here we take two variables number of frozen number of columns.
Now the defense will come that you are going to take in rural ways or column wise.
So let's say if the valley of M is let's say 3 and and is 2.
So basically what do list situation.
So I'm going to have clear rules and only two columns so please rows and two columns so this is a situation.
This is 0 1 2 and this is 0 and 1.
Now let's talk about railways input so if you want to take in brutal ways let's take input for the name
of the arrays.
Name of the to the arrays B.
So first you will take then put 4 0 0 you will write seen 0 0.
Then you will write 0 1 then you will write 1 0 so this is for the first row.
Cholesterol has been over.
Now taking input for the second to an index is 1.
So since the first column this is the second column then so then I will take the input for this and
now take the input for the third row.
So you will write.
So this index is two commas 0 so to zero and this one is actually 2 1.
So you will write to 1 and again seen.
So this is taking input rule wise I am thinking and put the weights.
Similarly you can do the opposite if you want to take and put column ways where you can do first fill.
First take the input for the cell then take the input for this cell.
So column wise is very similar to that always.
So for now let us concentrate on the ways because everyone uses revise revise is more popular.
So if you want taken But Roy's what quote We have to write.
So if you can see what we are doing here.
So I need two loops.
I'm going to take in three ways.
So I need to loop so one loop for hydrating over the rules and second loop for iterating over the columns.
Simple.
I am repeating myself.
I want to take input railways so I need to loop one loop related or what the routes and one loop related
or what the columns.
Simple and what we have to do so for each row for each row I have to take input for all the columns.
Similarly for the second row I will take input for all the columns.
Similarly for the third row I will take input for the third column for the fourth row.
I will take input for the fourth column to two loops will be there.
So the outermost loop will either rate or what the rules.
So let's say I equals zero number of rules are m so I listed them and I plus plus so this is the loop
for trading or whether it was normal for each.
I have to I read all the columns.
So one loop inside this bigger loop.
So this is for real.
So this loop is going to migrate over the rules and we know that for each all I have to take the input
for all the columns.
So let's take a variable j so J quizzical how many columns out there.
So there are n columns to g list and N G plus plus.
And again this index is very similar syntax is very simple C in the name of that is B.
And I will write I yet rule and git column simple yet rule.
I use the rule you can see I used the rule and g at column so g is the column.
So this is the way I will take input from the user in that way.
I used to take input like this I equals zero.
I left an N A plus plus and I used to write C in e of I so the idea is very similar here.
I was just I over the area because the area was one dimensional but here we have two dimensions.
Since we have two dimension then it is obvious that we need two loops.
So this is the outer loop and this one is the inner loop again very simple first we have to get rid
of what the rules.
And for each rule I have to enter the order column because I'm taking input railways column.
What will happen.
So this will become outer loop and this will become inner loop.
Just the opposite so.
Now let us write the code and let's see how to create a three Matrix so let us create a two the matrix.
So I do two dimensional Larry let's say the name of that is e the number of those hundred and let's
say the number of columns that hundred now what they have to lose for taking the input from the user.
I need to take how many rules are and how many columns.
So give me how many rows and give me how many columns.
Now I am taking in vertical ways.
So I need one loop.
Do I know what that was.
So I am I iterating over the rows and now I need one loop for iterating over the columns.
So for each and all I have to either do the column so I equals.
So we have to take another variable so Jake will see zero g list and n and G plus plus and then I will
take seeing it off I I get through and G column.
So this code is exactly the same as we discussed here.
Exactly same code.
So what I'm doing it I am I dating order.
And for each rule I am my dating order column.
Then take the input I get through and g at column so let's try to run our program and let's see everything
is working fine or not.
So first I have to give the value of I mean.
So let's say I want two rows and columns.
Now it is waiting for my input.
So how many elements I have to give or two in two three to cross three.
So I have to give six elements.
So let's say the elements are one two three four five and six and press enter.
So basically I have a code is working fine.
Our code is properly taking our input.
Now for this for this input what will be our metrics.
So our metrics is going to be very simple so you give the value of so you give m equals two and you
give any quiz three and then you give six entries.
So one two three four five six so if you will draw the matrix it will draw due to their mission Larry
you need tools.
So tools and you need three columns.
So three columns and then you give six entries one two three four five and six.
This is to include three metrics.
This is 0 1 and 2 this is 0 and 1.
So this is the input.
Now let us try to print this metrics.
So I want to print this metrics and I want to see how many metrics look like.
So again we have two option.
So first is to always print the metrics.
So print the first rule.
It will print the first rule 1 2 3.
Now print the second doing 2 4 5 6 and the second option is let's print the column.
Just like taking input.
We can also print column bytes for example print the first column so it will be 1 4.
Now print the second column so it will be 2 5.
Now print the third column so it will be 3 6.
So let's print otherwise and then we will also print the Columbine.
So for printing it always if I want to print ways how will I print again.
Just like taking input.
Where do we look we will need two loops.
What I want to do so for each row for each row I will I to the weather column and I will print the content.
Similarly for the next row I related order column and I will print the content.
So I need two loops.
So the first loop is going to a trade or whether those two equals you do a less than M and A plus plus
and for each row what we have to do we have to print the content.
So for printing the content I have to I trade over the columns.
So j equals zero g less than N N G plus plus and print the content to see out the name that is B I want
to print I utero and g at column now after printing that all.
So after printing the rule after printing the all I have to go to the next year.
So for going to the next row I will write C out and line simple.
So let us Sprint our metrics through ways so this the old line is basically for going to the next level.
Simple.
So we will give this input and let us sprint the roadways.
So let's see
what printing railways.
Let me write here.
I am printing railways and this is also railways so we can just copy the code copy the code and pasted
here.
So what we are doing instead of seeing what I will write I will write C out MySQL.
We are printing the content.
And after printing window.
So for going to the next rule you will write C out and line and that's all.
So this is the railway sprint so I have basically two rows and columns and I have to give six elements.
So the elements are one two three four five and six.
And this is so okay.
So I didn't give the space.
So that's why they are printing.
That's why that's why my output is veered so let's give the space so I am giving spaces between the
elements.
Now output will be incorrectly two rows three columns.
Now to give six elements a one two three four five and six.
So this is the content of the two dimensional area railways.
One two three and four five six.
You can see one two three and four five six.
So I will call this printing railways output in the correct manner.
Now let us try to print column wise so if you want to print columns What do you have to do.
Again very simple.
What do we do.
So for each column I have to trade or whether it was just we will do the opposite.
What I am saying so what was it always so it always says I try to weather rules.
And for each it'll printed the column what column by says
you a trade or weather column.
And for each column you will print that all simple.
So basically what will be our record.
So our code will look like this.
First we have to trade all the columns.
So for right trading with a column so I so I equals zero.
I list and a number of columns that N and a plus plus.
So I am migrating over the columns.
And for each column I have a total with the rules so remember M is rules and is the number of columns.
So you can see here rows and columns.
Similarly this is columns and
so I am migrating over these rules.
Now for each column we have to trade or whether it was so j equals zero g list an M C++.
I will simply write C out the name of the edit is B I want to print a yet column.
So if you want to print diet column so I will come here and Deer Trail.
So here it was A.G. But here what is I.
So this is I.
And this is G.
So Jay's actually derail and 1st index so.
So this one this is actually it'll and this is column so here you have two right.
J first and then I.
Because Jay's rule i e column and after printing one column for going to the next column you will write
a c out and line and that's all.
So this is printing column weights.
This is how we will print column wise.
Simple.
So what should be our output.
So our approach would be 1 4 2 5 and then 3 6.
So let me write this called.
So this is the way sprint now I want to print column wise so let's print
column by is so approach is very simple.
We have to write trade with the columns so i equals zero.
I less than anyplace else I am taking over the columns.
And for each column I have to iterate over that it was so j equals zero.
Similarly G less than M.G. plus plus and then I want to print.
So the name of the ad is B.
I'll get a name that is a.
So I want to print my dear true and I get column and we will give spaces between the elements and after
printing the one column for going to the next column.
Right.
She out and Lane.
So this is all.
So this is column wise.
Now let's see
number of rows are two number of columns are three and elements are 1 2 3 4 5 and 6.
So this is it always print.
We have seen already and this is column I sprint 1 4 2 5 and 2 6
so you can compare
so you can compare both.
So this is always just like this one and this is column bytes 1 4 2 5 and 3 6 1 4 2 5 and 6.
So our goal is working.
Hundred percent correct.
So this is the complete core
now in the next redo.
We will discuss how we can initialize our duty.
I will see you there.
Bye bye.