 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can find out maximum and minimum element from diagonal of a matrix by passing 2D array into function. Before starting, you can note my information. You can follow or subscribe my YouTube channel through the URL youtube.com slash sanjaygupta underscore tech school. You can download my programming app Tagmiss which is available on Google Play. Now I am going to implement the solution of this problem with the help of C programming. So first time including a header file that is STDIO.h then I am declaring two functions. First one is maximum. So this function declaration is for maximum function. Its return type is integer and it will receive an argument of integer type and that argument will be integer 2D array and its dimension is 3 by 3. Now I am declaring second function that is minimum. This is function declaration. Now I am defining main function. Inside main function, I am declaring a 2D array then IJ variables and then M. Now with the help of printf, I am going to display a message. Enter elements on console. Now to receive elements, first time implementing I loop followed by J. So this is the combination of nested loop. So to receive elements of 2D array, I have to use nested loops and these nested loops will be repeating scanf statement so that elements of matrix can be stored inside a 2D array. Now first time calling maximum function. So this statement is function calling. The result will be received inside m variable. So I can print it on console using printf statement. Now I am calling second function that is minimum. The result will be received inside m variable. So I can print the minimum. So this way I have implemented the main function. Now first I have to define maximum function and then minimum. So I am implementing definition of maximum. So this will be function definition. Inside this function definition, I am declaring 3 variables. After declaration of variables, I am again implementing nested loops inside this function. First loop is I which will provide row indexes. Second loop is J which will provide column indexes. Now inside this loop, I am implementing if I w equals to J. So this is the diagonal condition. If I is equals to J and aij is greater than m. So now you can see the condition. If i and j both are equal, then only they are pointing to the diagonal element. If this first condition is true, then second aij greater than m will be checked. If second condition is also true, it means the element is on diagonal position and it is greater than m. Then we can assign aij into m variable. So this way I am finding out maximum from the diagonal element and this diagonal is main diagonal or you can say major diagonal. So after completion of this loop, I can return value of m. So this is the complete definition of maximum function. Now I am copying this code and I am pasting it. So this definition will be for minimum. Here I am assigning 32767 and a of i j less than m. So now this code is for calculating minimum. So here you can see two definitions are available. The first one is maximum and second one is minimum and both are checking maximum and minimum, which are available on diagonal position. So now I am executing this code. I am entering the elements and you can see the output diagonal elements are 159. So maximum is 9 and minimum is 1. So the program is working properly. Now let's check it again. So this time I am entering different values. You can see the output six is the maximum and three is the minimum and diagonal elements are four, six and three. So this way you can see program is working properly in both the cases and you can check it for another matrix also. So here I have passed two d i into function. I have implemented two functions maximum and minimum and both are working on only diagonal elements. So this way I hope you have understood the logic behind this problem, which I have demonstrated you in this video. If you want to watch more programming related videos, you can follow or subscribe my YouTube channel through the url youtube.com slash sanjay gupta underscore tax school. You can download my programming app tech image, which is available on Google Play. Thank you for watching this video.