Category
š
LearningTranscript
00:00Hello everyone, today I am going to explain program of double dimension array and in this
00:10program I am going to cover to display the matrix 2 by 2.
00:18So if I have to display matrix 2 by 2, how I am going to do this?
00:23For this 7th number program I am going to perform that is to display 2 by 2 matrix ok.
00:36For that I have to use double dimension array and when I declare double dimension array
00:49the first two represents to the rows and the second one represents to the column, it will
00:59be like this.
01:00Let me again write down how the declaration will be.
01:08It will be like int a, the first one two represents to rows and the second one represents to the
01:16column.
01:17As I have to store the values in rows and columns, so at the run time the memory which
01:23is going to allocate is going to allocate in this way.
01:28This particular cell, this particular memory space will be called the 0 row 0 column ok.
01:36Then row will be the same but the column gets changed, so this particular cell position
01:41will be called 0 row first column, then the rows then the row gets changed, so this particular
01:48cell will be called first row 0 column and then what first row first column.
01:54So in a sequence way the memory is going to allocate and then values are going to store
02:00inside it.
02:02And I have a draw in this way in a matrix form as I have to make the program of a matrix
02:10ok.
02:11I have shown thus values in the location in a matrix form ok and in this way the values
02:20are also going to display ok.
02:23But actually the memory location which is going to allocate that is allocate in a sequence
02:29form ok.
02:31So I am going to quickly make the program, as I have explained that this is the 0th row
02:40first column and in the 0th row first column this is the first value which is stored.
02:45In the 0th row first column there is the second value which is going to store, in the first
02:50row 0th column there is another value which is stored, in the first row first column this
02:5720 is going to store ok.
02:59And then the same formation as for the convenient I have explained in a matrix form the display
03:09also will be in the same way 20 10 30 and 20.
03:12So how to do this for that I have to apply loop within loop ok and here I am going to
03:22make the program of it to store the values inside that double dimension array and then
03:30to display in a matrix form.
03:32So let us see, let me save also it ok, first thing what I will do I will declare double
03:51dimension array that is int a 2 and then again 2 which is having two rows and two columns
04:01ok.
04:02With it I will use two variables also i and j, i is going to go with the rows and j is
04:09going to go with the columns, here I will give a message what input values ok.
04:19So I have given a message here values which I have to input, so to input it I have to
04:23apply the loop i equals to 0 then what i less than equal to 1 and i plus plus ok and inside
04:34it I will again apply the loop that is j equals to 0, j less than equal to 1 and then what
04:41j plus plus ok.
04:44So the second loop is going to go to the column, the outer loop is going to go to rows.
04:49Now with the scanf I will use %d, and a i and then what j ok, in this way the values
05:03are going to store inside the double dimension array but I have to display it in a matrix
05:10form, so here I will give a message display of values in form of 2 by 2 matrix ok.
05:35So to do this what I will do, I will again apply the loop for i equals to 0, i less than
05:44equals to 1 and then what i plus plus inside it I will again apply the loop for the columns
05:51to cover i j equals to 0, j less than equal to 1 and then what j plus plus ok and then
06:02I will write on what printf %d, and sign and sorry not and sign then I have to give
06:16the location a i and here what j and below of it printf some spaces ok.
06:31When the inner loop will terminate then I have to take the cursor on the next row for
06:36that I will use what slash n, so I hope everything is fine and it's going to work perfectly.
06:45Let me save it, just click on build ok and run the program it's asking me to input the
06:54values so let me input the four values ok.
06:59Now let us press the enter key and I press it so it is displayed in the 2 by 2 matrix
07:04form ok.
07:05So let us understand when I have applied the loop, when I have applied loop within loop
07:10and we have understand how the loop within loop works, I have explained the programs
07:15of loop within loop how it works in my previous videos ok.
07:20So it will start the value of i is what 0, 0 less than 1 condition is true, it will come
07:26to the inner loop the value of j is what 0, 0 less than 1 the condition is true, so we
07:31are talking about 0 row 0 column position that is at this position ok.
07:36Suppose I input 50, so the 50 is going to store here in 0 row 0 position ok of double
07:45dimension array then the value of j is going to increment by 1, 1 equal to 1 the condition
07:51is true.
07:52Now i is what 0 but j gets changed it's 1, so we are talking about 0 1 position, so 0
07:591 position is where this one, so the next value which the scanf is going to read and
08:05store that is inside the 0 and 1st, 0 row 1st column ok.
08:12And again the value of j is going to increment to 2, 2 less than 1 condition get false it's
08:17going to the outer loop, the value of i is going to increment by 1, 1 equal to 1 the
08:23condition is true again it will come in the inner loop it will start from its initial
08:27value the value of j is what 0, 0 less than 1 the condition is true.
08:32Now which position we are talking the value of i is 1 but the value of j is what 0, so
08:39we are talking about this position, so suppose we have input 85, so that is going to 86 that
08:44is going to store in this position then the value of j is going to increment by 1, 1 equal
08:52to 1 the condition is true, now this time the value of i is also 1, the value of j is
08:57also 1, so the next value which is going to store that is in the 1st row 1st column ok.
09:04Now these values are stored but we have to display in a matrix form, so for that I have
09:09again applied loop within loop ok and I have given a message first again the loop will
09:15start the value of i is 0, 0 less than 1 the condition is true it's come to the inner loop
09:20the value of j is 0, 0 less than 1 the condition is true we are talking about the 0, 0 position
09:26of an array from here that the value is going to display on the screen with some space also.
09:35So what is the value inside the memory it's 50 that is going to display on the screen
09:40ok then the value of j is going to increment to 1, 1 equal to 1 the condition is true,
09:48so the value of i is 0 but the j gets changed to 1, so we are talking about the 0, 1 position
09:56that is this position, so value will come and then after some space it's going to display
10:04ok then what will happen the value of j is going to increment to 2, 2 less than 1 condition
10:11get false it will go to the outer loop the value of i is going to increment by 1.
10:16Now the value of form of i from 0 it's now 1 it will come to the decision part 1 equal
10:22to 1 the condition is true again it will come to the inner loop which is going to start
10:28from its initial value that is 0 will come to the decision part 0 less than 1 the condition
10:33is true.
10:34Now this time the value of i is 1 but the value of j is what 0, so we are talking about
10:41this position 1 0 ok, so the next value which is going to display ok that is on the next
10:48row because why it's going to display on the next row because when this loop was terminated
10:57when the value of j from 1 when it was 2, 2 less than 1, so when this inner loop terminated
11:06this it find what printf and it's having what slash n the cursor which was blinking after
11:16the display of 70 ok it will come here down to this position after 70 it's came down and
11:25then the value of i increment to 1, 1 equal to 1 the condition is true it will come here
11:33to the inner loop inner for loop where the value of j is what 0, 0 less than 1 condition
11:40is true.
11:41So now this time we are talking about 1 0 position ok, so what is the value inside the
11:461 0 position that is what 86 that is going to display on the screen ok I hope you understand
11:52with some space ok then the value of j is going to increment by 1, 1 equal to 1 the
12:00condition is true now we are talking about the first row and the first column as the
12:04value of i is 1 and the value of j is also 1 ok.
12:08So let us see what is there in the first row first column it is 90 so after some space
12:13it's going to display then the value of j is going to increment by 2, 2 less than 1
12:21condition gets false this loop will terminate the cursor will come on the next row by the
12:27use of slash n it will go to the outer loop the value of i increment to 2 ok it will come
12:34to this part to the decision 2 less than 1 here also the condition will get false but
12:40we will get the final result that is in a matrix form in a 2 by 2 matrix formation we
12:50get the result ok so this is the program friends which I have explained of 2 by 2 matrix
12:59in the next video I will explain something else thanks.