 Hello everyone. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So today we are having day 17 of the sales C and C++ coding bootcamp. And in this session I will be discussing about 2D array that we use in C programming. So yesterday I discussed about the concepts and few programs. So today in continuation that I will be discussing few more things with you. Right? So we will be implementing few more programs. So before starting the session, I just want to show you about myself. So if you are watching this session for the first time or like you are on the on the platform for the first time and if you want to know about me. So with this slide you will be able to know about me. So just go through with it and be consistent, do regular practice. If you have any doubt you can join this telegram group. And if you want to receive session reminders, so you can just follow Sanjay Gupta Tech School on YouTube, LinkedIn, Instagram and Telegram. And all the important links are available in the videos description. So yesterday I explained all the concepts. So if you have not gone through with that recording, so you are that session. So recording is available, you can just go through. And in today's session, I will be discussing about a few programs that we can implement with the help of 2D array, right? So that I'm going to implement one by one. So here you can see the list is available. So total five programs I will be implementing. So first program is like some of rewards diagonal offer 2D array or metrics, right? So yesterday we discussed like how we can calculate some of diagonal. So if I show you that program, so here you can see this was the solution, right? So basically I'm removing this. So here we have the solution. So what we did first of all, we received all the elements of 2D array and 2D array was of size four by four. So if you want to have a diagonal, so in case of diagonal row and column size should be same. So after receiving the values, what we did, we just implemented this logic where if if I is equals to J in that case, like it is a diagonal value. So if we consider four by four matrix, so we have two diagonal, one is main diagonal, which goes from left to right. And one is like it's reverse diagonal, which is not the main diagonal. So that is basically that basically comes from right to left, right? So if you want to have some of those values, so what I'm going to do here, I'm going to copy and paste it. So we'll be having both will be having both the sum. So it is some of main diagonal, right? So I'm having one more variable, some one equals to zero. And here it will be having the values some one, right? So values will be added here, but we need to modify this condition. So initially, like for main diagonal, we know if indexes are same, then then only like we can consider it a diagonal value. But if we talk about reverse diagonal, right? If we talk about reverse diagonal, so what happens in in case of reverse diagonal, if you consider the indexes, right? If you consider the indexes, so basically, reverse diagonal index sum is equals to either row size or column size, minus one, right? So let me just show you that thing. So yesterday, I showed you this one, right? So it is basically three by four. So just just ignore this last column, right? Ignore this last column. So let me just modify it. So I'm just deleting it, right? So we have three by three matrix. Okay? So if we if we talk about the main diagonal, that is one, six and 11. So one, six and 11, this is main diagonal and three, six and nine, this is reverse diagonal. So for three, we have indexes zero to four, six, we have index one, one for nine, we have index two, zero, right? So this way for three, six, nine, whatever index we have, like zero to one, one or two, zero, their sum is equal, that is two. So if your matrix is three by three, so in that case, your reverse diagonal index sum will be equals to row minus one or column minus one, right? So this way we'll be able to calculate the result. So now moving on to the requirements, so we need to calculate some of reverse diagonal. So here, what I'm going to do, I'm writing i plus j double equals to three because row or column size is four. So index sum will be minus one, that is three. So if I add i and j, so the result will be equals to three. So in that case, like if we are adding the index i and j, if both the indexes are equals to three, so in that case, value will be added to sum one. Sum one is a variable that we created. So once this loop is completed, so the result will be available into sum one. So now I'm going to show that sum of reverse diagonal and here I'm using sum one. So sum and sum one, both will be displayed, right? So this way now I'm going to execute this code. So we need to enter 16 values. So I'm going to modify this code a little bit. So before showing this, what I'm going to do, I'm going to show the values of matrix so that we can compare accordingly. So I'm just copying it. So here I'm going to use a printf which will be showing you entered below matrix. And here instead of scanf, I'm using printf, right? So this way this block will be displaying the results and 44 loop will iterate and a of ij will be displaying the values. So this way we'll be having the matrix that we are going to enter so that we can see the sum, right? So here what is happening? We need to enter four by four values. So 123456789101112131415 and 16. So I entered total 16 values and okay, so one more thing, we just need to add tab space. So here I'm using backslash t so that one tab space will be available in between the values. So again, I'm going to enter the values. So I entered 16 values. So this time you can see we have a matrix so 161116. So if we add these values so 18 and 16. So sum of main diagonal is 34. It is showing 34 for reverse diagonal as well. So we have values as four, seven, ten and 13. So if we add these values, so it is also 34, right? So coincidentally all the values that we have on main diagonal and reverse diagonal, their sum is 34. So this way, like if you implement 2D array, so what is happening? First we are reading the values, then we are displaying whatever values we receive from the user in form of matrix, then we are calculating some of main diagonal, then we are calculating some of reverse diagonal. So you can see the conditions are different. So here we have Iw equals 2j and here we have i plus jw equals 2 3, right? So this 3 is like total number of rows minus one or total number of columns minus one. And then I just displayed some and some one. So I hope with this demonstration, you are able to understand how we can calculate some of main and reverse diagonal. Okay, so now moving forward, next is read two 2D arrays and store the sum into third 2D array and display the result, right? So we need to declare some arrays here. So I'm just removing it. So we have a, so I'm just reducing the size to 22, then B of 22, then C of 22, right? So here I'm entering two into two, then two, right? So this way enter first two by two matrix, then I'm just copying it and pasting it here. So it will be for enter second two by two matrix. And here instead of A, I'm going to use B. So this this piece of code line number six to 11 is basically reading first matrix. And line number 13 to 18 is basically reading second matrix. Now we just need to perform addition operation and then we'll show the results. Okay, so for addition purpose, I just pasted these lines again. And here instead of scanf, I'm going to write C of ij equals to A of ij plus B of ij, right? So this way, matrix values will be added. And what will happen? All the index is like a ij index will add with a b ij index. So index number will be same. So the same index values will be added and the result will be stored in the same index but into C matrix. Now here, we can show the sum. And again, I'm writing to so that it will iterate like row will iterate twice and column will also iterate twice. And we need to display C matrix with the sum. And these things I'm using. So what I did first I read first matrix, then I read second matrix, then I perform the addition operation, the result will be available into C matrix. And then C matrix result will be displayed on the UI. Okay, so now I'm going to run this code so that you can understand. So for first matrix, I'm entering two four times. And for second matrix, I'm entering four, four times. So the resultant matrix will be showing 6666. Because of we entered two in the first matrix, we entered four in the second matrix. So the values will be added and the result will be displayed as six. Right? So this way, if you want to perform addition operation for two matrices, so that is possible. Then we have find out maximum from a 2d array. So it is also simple and straightforward. So what I'm going to do here, I'm going to create one variable as max. So here, we need to assign max equals to a zero zero. So first element will be assigned into this. And then we can write if if a of ij is greater than max, so max will be equals to a of ij. Right? So if array element 2d array element is greater than max. So what we are doing, we are just assigning that array element into the max so that we will be having a new max value. And this piece we can avoid because we just need to display the maximum. So here I can write maximum equals to max. Right? So this is basically to read a 2d array, two by two, total four elements we need to enter, then max will be having the initial first value. Then with this loop, we are comparing array element with max variable. So if array element is greater than max, so that array element will be assigned into max always. Okay, so I'm going to run this code. So I'm entering 1234. And here you can see max is four. So this way code is working fine. Now, next we have find out minimum. So if you are able to find out maximum, so it is very easy for you to find out minimum value as well, because in case of minimum, you just need to do little bit changes. So here in in place of max, I'm just using min. And here also min. So min will be having the first element that is available on a 00 location. And after that, what I need to do if a of ij is less than min, if array element is less than minimum, so what will happen minimum will have that array element. Okay, so it is just reverse of that max logic. And here I need to write minimum. So so it will be like minimum equals to percent d and it will display the min value here. So this way I hope you will be able to find out minimum. So if I click on run, so I will be having the results. So you can see minimum is four. I entered 1234 as values, but it is showing minimum as one. So this way, like if any time, if you want to find out maximum and minimum from an array, like 2d array, so that is possible. Now last is very simple, like we need to print transpose of a 2d matrix or 2d array or matrix. So what happens whenever you have a 2d array, and if you want to print transpose of that 2d array, so basically what happens, whatever values we have in rows that displays in column, and automatically whatever we will be having in the column, so it will become the row, right? So here what I'm going to do, I'm going to implement this logic for you so that you can understand how actually it is working. Okay, so first of all, like this code will be same and we just need to display. So I just need to modify this code. So here you can see what I did. I just modified the code. So initially we are going to read the values from the user and later on, I'm trying to display the values in form of transpose, right? So if you see the code, so if you see the code, so what is happening here, first time reading the values in two by two matrix, and then I'm showing them on UI, but here there is a minor catch. So whenever you are showing the values, you will be using j i instead of i j. Okay, so what will happen, whatever values you are having on rows that will display on column, and column will automatically convert into row. So this way you will be able to display transpose of 2d array. So if I run this code and enter one, two, three, four. Okay, so let me show you two results. So this this first part printing part will display what you entered. And this will be showing the transpose. So I'm just copying it and here I'm pasting it. And here I need to write transpose of matrix, right? And here I'm writing i j. So this this first piece of code will display matrix as is as you enter. And the second piece of code will be displaying its transpose, right? So what I'm going to do, I'm just clicking on run. So here I'm entering one, two, three, four. So now you will see to output what you entered one, two, three, four, right? Whatever value we enter that will be arranged in row wise manner. But if you see the transpose, so it is showing one, three, two, four. So row became column and column became row. So this way if you want to measure transpose of a matrix, so you just need to change the index. And if row and column sizes different, like it is two, three. So here what you need to write three to just opposite loops will iterate differently here. So this way I hope you are able to understand how we can display transpose off of matrix or a 2D array, right? So I hope with the with these exercises, if you if you practice these exercises as your own, and if you are a BTEC student or non technical folk or technical folk like you, if you any any stream you are related any age group you are whatever degree you have, but if you want to stand on your coding skill. So I think the these programming related boot camps will be beneficial for you. So if you see this session tracker, so here, all the session links are available, you can go through, right? So everything I will be explaining in detail. So for BTEC students, this is very much helpful, right? If you are a BTEC student, and if you go through this sheet, so it will be a game changer, you will you will love programming, right? So everything I explained clearly in every session. So you just need to follow all the steps, right? All the sessions if you follow, and whatever exercises I have demonstrated in all the session. So if you follow them, you will be able to learn the programming. So soon I will be adding some one day area and two day related programs here as well. So you can go through with those programs so that you can understand more. Right? So this is it for today. I hope you understood whatever I demonstrated. And if you are watching live, thank you so much. If you are watching the recording, thanks to you as well. And if you like the sessions, if you like the bootcamp concept, so please share a review or feedback and it will keep us motivated. And on this platform, like lots of bootcamps are already running. So as I promised you, like we did lots of things and doing as well. And in future also, like right now I have planned two more bootcamps, those I'm going to start from September. One is based on Davops and one is based on data science and AI, right? So as I promised you, like all these things are happening, things are taking time, but they are happening. So thank you so much for joining the session. So next session will be next week and we'll share the reminder for next session until then if you are following these bootcamp sessions, so you can do some practice. Thank you, everybody. See you next week with this particular session. Rest of the sessions are planned. They will be happening as scheduled. Thank you, everyone. See you next week for this session.