 Hello friends, I am Sanjay Gupta. Welcome back on Sanjay Gupta Tech School. अब दित रहें सी लेंवेज भीटियो सीरीज और इस वीटियो में हम दिसकस करेंगेद अब तूदी अरे. तो ये लेक्चा नमबर 17 है. पिच्ले लेक्चा नमबर 15 और 16 में में आपको वंदी अरे बताए था. तो 15 में वंदी अरे का अंट्रोट्चन दीा था और 16 में बगद सब दोडी प्रुब बुग्टियो सरी लेक्चन ता अपको एक वैं वआत को इस्टीं कियो दें. अर इस वीटेो में हम 2DRA का बेसेक और कुछ इंदमपल्स अन 3DRA का एक एक अचमपल में अपको बताउग़ा अपको बताउग़ा. 3DRA, generally अपके अपके सलीवास का पार्त नहीं होता है. तो आप यहाँ पर देखोगें कि जो फ़ुस्ट आरे है, वो तो दिस्पले कर रहा है, तु और जो सेकंट आरे है, वो दिस्पले कर रहा है. तो विस्टरी के से जो वह दो वन्दी अरेज नहीं है, उनके वेलुज कोम अपको अपको बताउग़ा. तो ये वहाँ पारत उस में प्रपरले डिस्पलेड नहीं है, तो अगर अपने अनड वाला प्रोगरं देखागागा याप को लगागागा कि ये प्रपरले इप्प्लेनी हो पारत फ़ाई. वी शके मैं असको रीकफोल कर दिया. आँ अब में 2D आ़े गो प्रोपर लिए दिसकस करना है अगर अगर मुसे कोई भी दाॉट दिसकस करना जाते है या देरेक्ली औनलें क्लास्न लेना जाते है तें मेरी दितेल से तो नोमली होता क्या लिए बीडियो देखने के बात बोसरे दाॉट स मनने आजाते है तो वउंडी आले मैं आप तो क्या बताया था अगर वह में बोछग स्वरी में लेलिस को स्थूर करना होता है उवह में भोछग स्वरूट स्वरी बЛाने बडेगे तो हम भोछग स्वरी बॉ़्� तोकोल,onnerना बार OF स्यात कोग अल आरे को भी और से आदिन्टीभ आरे को फ्रैम कर दए थे।पह तो जैसा की अन देफीनेशन में लिखावा है। अच्चचचचा जो अच्च्चाची आरे को अच्चिच की आख्च्चाची बफ्रह्ता दीटा तो ऐक्च्चन कारदा। अगर आप देक्लेड़िशन देखेंगे तो सब से फ़ले नहीं डेटाईभ लिखना होता हैं दैन हमें आरे का नेम मेंशिन करना होता हैं देन नमबर अप रोज यज नमबर अप कोल्म्स और यज यज का एक एक जामपल हैं देटा टाईप यज यज आरे नेम यज के नमबर अप रोज तरी और नमबर अप कोल्म्स आर फोल तो अब एक पर यज को थोड़ा सब प्रक्तिकल आस्पेक्त से देखते हैं तो आप यज कैसे होगा गी बोछद सरे वंदियरे बनाने पर हमें तो उसको अपन एक बर देख लिएते हैं तब सपोस करो की एक खास के अंडर शिक्ष्टी स्टुड़ेंस हैं और हमें छी सबजेख्स के माख्स स्टोर करानें तो आप क्या गरेंगे पहला वं दियरे बनाएंगे जिसका नाम होगा आम वन नाम वन बनागे सबजेख्स के आप बनाखिस अप खुट़ेंगे जाँई स्डीडियरे बनागे तो अगर सबजेख्खिख्ष के माख्स और किदने स्थुड़ेंगे अप शिक्ष्टी M260, M360, M460, M560. तो आप देखने की मुजे जितने सबजेख से हुतने वेरीबल सेहां पर देखने पड़ने पड़ने. तो मैंने तोटल कितने वंदी एरे बना है? चे. और आपने देखने की सब का जो दिमेंचन हो फिगष्द है. अपनको और वंदी एरे में स्टोर करने है. तो आपको क्या करना बड़ेगा? चे वेरीबल, M1, M2, M3, M4, M5, M6. इंको मैनेच करना बड़ेगा. चीके अप सबचोस चे सबजेख सोग़े आपके एक एर्या एक समिस्टर के. आगली एर में और सज्टिख सोच़ा है पर अधके वीरय य circumstition , बद़ेगी फ्रु करworking इस पास करट Над मागने �аксपना, जो संगा संगाो जे संगा किकल� hedad na, je aspana shakina, cleared now you are getting the example that there will be 3 rows and 4 columns and the 2nd example is there will be 2 rows and 3 columns in every row total number of elements, if you multiply them it will get the according like 3 x 4 12 elements will be stored in 2D array then 2 x 3 means you can store 6 elements तो अब अगर अपन एक दीग्राम के तुस को सबजने की कोशिष करें तो यहाप देख सकते हो, की एक मेट्रिक्स ताएख का एक 2D-RA मनाया है तो 2D-RA मेट्रिक्स की तरे रीबिजन्त होता है तो जेसे में आपको एक जमपल बतायाता है, इस में देमेंचन कितना है, 6 by 60 तो total number of rows कितने हो जाएंगी? 6 तो total number of columns कितने हो जाएंगे? 60 अब अब कोगे की हमें जैसे 1D-RA में आपको में बतायाता है, index 1D-RA में क्या बतायाता है, index तो जिनोंगे मी 1D-RA वाला वीडियो नहीं देखा है, वो पहले उस वीडियो को जरुर से देख लें, क्योंगे 1D-RA की बहुसरे term में आपको युस कर हूँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँ� बहुँँँँँँँँँँँ बहुँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँ तो एक्छिली मैंरी लेगा अब को मिलेगा, तो वो यह अथा है ये रोवाईज मैंरी अलोकेश्यन है, और अप असको बोल सोटते है, कंतिनिस मैंरी अलोकेश्यन से थो तिससक्रोग, this is 2nd row and this is 3rd row so if you see first row index 000020203 so you can see 000020203 then 10111213 then 20212223 and all the values are stored in the same sequence so you can use this format to understand it but actually memory is allocated this way so you should know that by default the memory occupied by 2D array is occupied by row wise memory and continuously so this way you will understand the declaration how to make 2D array then memory is allocated now let's talk about initialization so as I told you in 1D array there are 3 things this is written as int a 1 is written as a equals to 5 and 1 is written as int b equals to 5 so this statement is called declaration because here only variable is declared after declaring the variable if you assign a value to it then this is assignment operation but if you declare any variable then the value is assigned to it so this is known as initialization we declared the variable for the first time and at the time of declaration we initialized some values so this statement is known as initialization so now let's see how to initialize 2D array so this is what I have told in 1D video how to initialize 1D array so now let's talk about 2D array so first example first example is rows and columns rows and columns are 3 so total number of elements is 6 so this is valid as I told you in 1D array we can't store more than size so 3 into 2 is 6 so total 6 elements are stored properly now the second example for initialization it is written note okay it is not valid why? we have told 2D array but we have not told column here total is 8 it is said that it will be 2 rows but it is not told how many columns will be in each row so 2 rows can be 4 elements in one row 4 elements in another row it can be 5 elements in one row and 3 elements in another row it is not known how many elements will be in each row and it cannot be automatically divided so on the second approach if you want to leave some blank then what can be blank? column size you have to fix it always so once you have fixed column size then you have to fix it and you will know the row size so column size is 3 so 1 pair of 3 means first row then 1 pair of 3 second row then 2 pair of 2 because third value is not available so this is third row so what is the value of row size automatically? 3 so always keep in mind as it is written in note at the time of initialization it is a must but row size is optional so third example is valid but second example invalid so I hope you understood if you still have any doubt then write it in comment section I will explain it to you or you can directly connect it through email or whatsapp so after initialization let's talk about how to read and print 2DRA so as I told you there are multiple rows and multiple columns so now we have to use nested loop so you have seen my video of nested loop which is 1DRA in which I have told you many patterns so now if you have seen pattern program then you will understand nested loop so I will request you to watch that video so if you follow the series properly then you will understand but if you see something randomly then you should know its basic so I hope that whoever is watching this video will know the nested loop so they will know that the first loop is called outer loop and the second loop is called inner loop when outer loop has one rotation then inner loop will finish its complete rotation so for example if I is 0 so J 0 1 2 3 4 times will go then when I will be 1 then J will go again 4 times then I will be 2 then J will go again 4 times meaning when outer loop is running then inner loop will finish its complete rotation then for printing also we have used nested loop so now practically I will explain to you how to read 2DRA and how to display its value so we will make a 2DRA whose dimension is 3 by 4 so you must have understood the basics if we go on the main ppt then you can see here I have told you declaration memory allocation initialization now we are talking about reading and printing after reading and printing where we will go directly on the program's implementation so first program is calculate some of all values for example in a matrix so I will explain to you so first let's see the reading and printing so that you can understand it well so I have declared a 2DRA now I will declare 2 variables IJ which is less than rotating loop then printf enter 3 by 4 matrix values first loop run for loop then equals to 0 then i less than 3 so the i loop will be repeated so let's run another loop inner loop column time will run so the value of column is 4 so how many times we are repeating j loop 4 times then I have written scanf percent d amp percent now see here we are writing index so I have told you that whenever we will access 2DRA we will have to function 2 index, 1 index will be for row and 2nd index will be for column so who is telling row index and column index then if we iterate it then i is 0 check the condition then it will be controlled on j loop so how many times j will run 4 times 0, 1, 2 and 3 so when j is repeating 4 times so the value of i is 0 when the index will be so what are the indexes when it will read first time then it will be a01 when it will read second value then it will be a sorry it will be 00 first time it will be a00 second time it will be 01 third time it will be a02 and fourth time it will be a03 so in this way j loop will repeat 4 times and 4 times it will be stored when j value is 4 then condition falls when inner loop falls then control will go on outer loop increment part so outer loop the i variable was 0 now what will happen 1 then it will check its condition when it will be 1 then j loop will run 4 times when it is 1 then it will repeat 4 times so j will start again from 0 so it means j value will be 0,1,2,3 but here i value will be 1 so what are the indexes of second row 1,0,1,1,1,2,1,3 so if you want to see in diagram 2nd row index 1,0,1,1,1,1,2,1,3 so that is what we have created through loop so in this way you can read the values of 2DRA now you want to display the values input as it is on screen and in matrix format so for that we copy these loops here we write a message you have entered then backslash and now i and j loop as it is will go printf, force and d now here we put backslash to put backslash t so that in between 2 values there will be tab space then a of i j now when inner loop will be finished so my requirement is after printing 1 row print the next value in new row so now i have to put curly basis here because i want to do grouping so i have already told you that with for loop you have to do multiple statements so you have to do braces so now with this inner loop only this printf will be repeated so when inner loop will be finished and all the value of 1 row will be printed then this printf backslash will bring this cursor on new line and then i++ will go from it value 0 to 1 again it will print the next row after printing what will happen the cursor will go on new line and it will come on cursor on new line means in matrix format so in this way 2DRA read will be printed let's compile and run this is saying enter 3 by 4 matrix now i will enter values so 1 2 3 4 5 6 sorry i entered wrong values i entered 4 values in first row so i will execute it again so 1 2 3 4 5 6 7 8 9 10 11 12 i entered 12 values and i also entered matrix format so you can input it like this now see output you have entered first row 1 2 3 4 printed then backslash and cursor on new line 5 6 7 8 printed 9 10 11 12 printed and the space in the middle is coming because of tap because we have printed this printf so tap space is printed so i hope you have understood 2DRA reading printing now quickly let's see 2DRA related programs so first program is calculate sum of all values so it will be very easy so many things related to 1DRA like we have written A of I so what we will write here reading printing you have understood so calculate sum of 2DRA sum of 2DRA ij sum equals to 0 read array now i told you at that time at 1DRA time we can do process reading or we can do 2 loops separately so it depends on your requirement sometimes you can't do processing in reading loop like in 1DRA we did linear search in linear search we did loops separately but we did addition in that loop so it is also possible here so i will put the curly basis from which we will be able to do grouping so now what i have to do as soon as this loop goes and value will be scanned so i have to perform addition here sum equals to sum plus A of Ij okay so now you have understood that this is inner loop value will read and it will add in sum when inner loop will be finished outer loop will increase again inner loop will go 4 times and then new 4 values will enter and add when both loops will be finished so all the elements available in 2DRA who will have the sum available and the sum variable so it will be displayed here sum equals to percent sum so it will read and the sum will be displayed but in 2DRA it will not be displayed again because i removed the loop of printing so it is 78 if you add the values from 1 to 12 then total will be 78 and if you have to test it more easily then we will enter every element as 1 so we entered total 12 values as of 1 so you can see that all the values we have entered total 12 values so we have added all the values available in the matrix then next program is sum of individual rows, columns and diagonal so now here a requirement is diagonal so in the case of diagonal you will have to see column size is equal but if you have to sum individual rows and column then column size can be different so now what we have to do so to add row and column we have to make a variable s1 for row sum s2 for column sum s3 for row sum sorry diagonal sum so it will store this is column sum and this is diagonal sum then we have performed reading operation and scanned now I am writing here this will be 3,3 here I am writing s1 equals to s1 plus pay off then s2 equals to now in this what we have to do we remove them from here we run a different loop because we have to do sum print now in these processes with reading you cannot perform calculation so here I have pasted them so now see this is reading section which is all 12 or 9 elements because you have 3 by 3 matrix so total will read 9 elements now we have to do sum and print so now we have to do sum print of individual rows 3 columns 3 columns so what we have to do we have to initialize s1 and s2 here also and here we have to write s1 equals to s1 plus a of ij and column sum s2 equals to s2 plus a of ji and when this loop will end when inner loop will end then we will print row and column so we have to do sum print of first row so now see sum of first row is in s1 and column sum is in s2 so we write percent d sum equals to percent d then we write i plus 1 comma s1 okay we copy this percent d column sum and this will end now we have to write i equals to j when row and column are equal then we will do s3 equals to s3 plus a of ij so what is diagonal when row and column are same if i show you through diagram so this is diagonal situation so for now forget this part focus only on 3 by 3 so 1 index is 00 6 index is 11 and 11 index is 22 so diagonal position value of index is same so if i and j value is same it means same index means diagonal location so we added it here normally for row we have used ai and j and for column we have used ji so if we talk about column this is first column 159 if this is first column let me change color for understanding if we talk about first column so what is index 001020 okay 001020 so if you see in program so what will be indexes here first time j is 0 i will also be 0 then next time next time j plus plus i will be 0 so this index will be 1 0 because j is written first here so if you want to write row then write ij column you can write ji so in this way as soon as this inner loop will be over then 1 row and column will be summed so we have displayed it here so when this loop will start again so s1 and s2 will be 0 because when we have to sum of second row then before second row and column it is necessary to reset from 0 and when both loops will be over then we will print diagonal sum so you will take print f diagonal sum equals 2% ds3 let's remove this so in this way individual row column and diagonal sum will be printed on screen so what should we do let's input 1,2,3,4,5,6,7,8,9 now you have to calculate first row's sum first row is 1,2,3 so 1 plus 2 plus 3 is 6 first column's sum so first column's value is 1,4,7 so 1,4,5,7,12 so this is also correct then second row's sum second row is 4,5,6 if you add 4,5,6 so 4 plus 5 plus 6 9 plus 6 is 15 so this is correct and second column is 2,5,9 so if you add it then it will be 15 so in this way it is proper diagonal value is 159 so if you add it then it will be 15 so in this way individual rows, individual column and diagonal you will be able to display all three and if you want to remove any particular thing then you can remove that statement so this statement we have written this is row's sum this statement we have written this is column's sum and this condition we have applied this is diagonal sum so whatever you want to remove remove it you can remove related printf so you can implement one particular thing in the program now let's talk about the next program that is print transpose of matrix this means that row has to be converted in column so it will be very simple so you have understood the reading we just have to print transpose print transpose of 2D array remove all these variables so to convert row in column I have just told you that we can write a of ij a of ji so that is the same thing we will use here I am writing in this printf percent d backslash t a of ji so this way the transpose will be printed and the things written here will be raised we will just put backslash n because we have to print value in new line so for this transpose printing we have written pattern so to print normal we have to write a ij if we have to print transpose of matrix then you have to write a ji so it will print value now let's execute it 1 2 3 4 5 6 7 8 9 so now you can see row is 1 2 3 which is printed in column form then here row is 4 5 6 which is column 7 8 9 that is column if you have to pick column here 1 4 7 then you can see row is printed so in this way you can easily print any transpose of 2D array if the size is different 3 by 4 then you have to change 4 by 4 and you can also print this way so this is what you can try if you have any doubt then you can discuss with me now last program is matrix addition and subtraction so let's see that too before that let me tell you an interesting thing we did diagonal sum we did two loops now let me tell you diagonal sum from one loop this is an interesting thing many times you can ask to do diagonal sum you have to do two loops from one loop so what will you do? you can write this this is so easy I have given both index here so I had told you that diagonal index is same 0 0 1 1 2 2 3 3 4 4 so when i is 0 then 0 0 when i is 1 then 1 1 so first a is 0 0 index then a 1 1 index will be added so we have directly taken that index which is available on diagonal position and then you print it so if we take it here see what is the diagonal value 159 and total is 15 which is correct so this is one loop through diagonal sum so it is very easy now let's talk about addition subtraction so for this we will have to make three 2D array so this is the first 2D array this is the second 2D array and this is the third 2D array so we will write enter first 3 by 3 matrix values copy this then paste so this will be enter second here we change it remove it again paste okay now what I will do I will print it so we take sum of store in third matrix okay and here let's put the basis okay now what we have to do after performing the reading operation we have to perform addition so there you will write cij equals to aij plus bi okay now as the values are added you can print it so here we will write %d backslash t and print cij because values are stored in c and when this loop will end then we have to go to the new line because we want to print matrix format in different lines so this is basically the combination of loop that is the loop it will store sum of 2 matrix and you want that there are 2 loops for sum and 2 loops for printing in that case remove this printf end paste this loop and mention it in the same format but the less loop your work is beneficial enter first 3 by 3 matrix so here we enter 1 4 5 so you can see 5 on every 3rd matrix now we will talk about subtraction so what will you write for sum subtraction and minus so the input you have made will have difference so as I have written 4 2 so what is the output you want addition subtraction both are same copy and paste so let's make the top sum let's put it on the bottom so here if we input values so let's say 4 sum is 6 difference is 2 so you can easily perform addition subtraction and you want to understand 2DRA programs so if you go in the description in the description so the first playlist is the link of this video series apart from that you will see 2DRA programs in C so there are many more problems related to 2DRA so through this video you will understand the basics of 2DRA so you can understand the tough programs now let's talk about 3DRA so 3DRA is very simple as I have told you when we make 1DRA when we make 2DRA then we store a lot of variables in a single variable when we make 2DRA then we store a lot of 1DRA in a single 2DRA now there are a lot of 2DRA so what can you make like for example let's take this how many 2DRA are here so we can combine these 3 2DRA and make 1 1DRA how will it be end A look here these are the dimensions these are the rows and columns and how many 2DRA are there who is telling that first dimension if I change here then it will be 3 2DRA and their dimension will be 3 by 4 if I make this 3 2 then it will be 2 2DRA whose dimension will be 3 by 4 so in this way we have to process them and the variables will be 3 i, j and k and if we talk about its reading and printing if we talk about reading and printing then add one more loop here k less than equals to 4 k plus plus and here it will come a, i, j, k now here dimension is 3 so this is 3 2DRA 3 by 4 so 1 2DRA of 3 by 4 will be total 12 elements and these 3 means 12 into 3 36 values you will have to store here so we will reduce its size we will do this we will do this we will do this we will do this 3 into 2 6 and into 12 so this will be 2 here it will be 2 and here it will be 3 now we have to print them now see there are 2 2DRA whose dimension is 2 by 3 so you will have to print it smartly now here j loop is running now this outer loop will tell how many 2DRA are there 2DRA actually will be printed j and k combination so now we remove this line we will do this we will do this 3 times this will be printing so this is 2 times this is also 2 times and this is 3 times and here it will be j this will be now this 2DRA will be printed so after this we will put the slash so when this 1 2DRA will be printed then we have to print 1 more 2DRA so for its gap we will put 2-3 backslash so these 3DRA basically we have performed through reading and printing now we will execute this so I have told you a basic thing when you will make a program on this you will have to put a little more mind so see this message I have not modified we will modify this now we will enter 2 by 3 matrix 2 2DRA we will read and we will read it in 3DRA so first 2DRA whose dimension is 2 by 3 so this 2 by 3 this first 2DRA is read then I am putting second 2DRA in which there are 5 sets now you will see the output I have made some mistakes so what is the mistake I did not write high because we have to tell which number 2DRA is through this so when we are printing you will have to use 3 dimensions so 1 2 3 1 2 3 this is the first 2DRA then 4 5 6 4 5 6 you can see first 2DRA 1 2 3 then I have put backslash space and then 2DRA so you saw I have made 2DRA through 3DRA so in this way I have completed the topics in this video in the next video we will read about string so I hope you understood 2DRA and if you have not seen 1DRA then you will also see 1D, 2DRA and 3DRA and in the video description you will get the video series playlist and you will get individual playlist which is 1D, 2D, string related to these programs so you can see many other programs and these are my details if you have any problem you can communicate with me because 1DRA, 2DRA, string these are very difficult topics if you are a beginner and you have many doubts you can discuss this in the next video which will be lecture number 18 and I will explain the string thank you for watching this video