 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can find out maximum and second maximum from 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 Techimace which is available on Google Play. Now I am going to implement the solution of this problem so that you can understand how you can find out maximum and second maximum values available in a matrix and we have to pass 2D array into function. So first I am including a header file. After header file inclusion I am defining the function max s max and it will receive 2D array as an argument and 2D array will be of integer type. So this statement is function declaration. Now I am defining main function. Inside main function I am declaring a 2D array. Then I and J variables. Now with the help of printf I am going to show this message enter elements on console. To read elements from user I am applying these nested loops. Here I will be providing row indexes and J will be providing column indexes. So with the help of this scanf I am going to receive all the elements from user. So these nested loops will be repeating scanf statement so that all the elements of matrix can be stored inside a 2D array. Now I am calling max s max function and I have passed a 2D matrix inside this function. So this statement will be known as function calling. At last I am writing return 0. So this is the complete implementation of main. Main function is only reading 2D array and then it is passing 2D array into max s max function. Now I have to define the definition of max s max function. So inside this function this is function declaration. So inside this function I am declaring some variables. So here you can see I have declared I, J variables. Then max and s max variables which are initialized with the element. Those these elements are the smallest number of integer range. So I have initialized these variables with this value because 2D array can contain both positive and negative elements. So these are the smallest element. So the element which are available inside matrix will be greater than these numbers. So now I am applying the logic so that we can identify maximum and second maximum. So here first time checking aij is greater than max or not. So if this condition is true it means array element is greater than max. So if array element is greater than max then I have to assign this aij into max. But the current max which is available in max variable will become second maximum. So first time assigning max into second max and then I am assigning aij into max. So now aij is compared with max if it is greater than then max will provide its value to second max variable and aij will provide its value into max. If this condition is false then I have to check another condition whether aij is greater than s max or not. So if it is true then I also have to check whether aij is equals to max or not. So again understand this condition. If aij is lesser than max then it can be greater than second max and we have to check that it must not be equals to max. So if aij is not equals to max and it is greater than second max then only we can assign aij into s max variable. So this is the complete implementation of these nested loops which are checking whether the array element is maximum or it is second maximum. Now after completion of these loops I can print the output on console. So maximum equals to percent d and second maximum equals to percent d then comma max and s max. So with this way I have implemented the complete solution in front of you. Now I am going to execute this code. So I am entering these different values. So you can see the output maximum is 6 and second maximum is 5 and you can see the matrix the largest element is 6 and the second largest element is 5. So the program is working properly. Now again I am executing this code. This time I will be entering maximum element twice. So you can see that 6 is available twice in matrix but still maximum is 6 and second maximum is 5. This is because I have applied this condition aij is greater than s max and aij not equals to max because of this condition the maximum is assigned into max variable only. It is not available in second max and second max is containing the second largest element available in the matrix. So if same elements are available in matrix then also you can recognize who is the largest number and which is the second largest element in the matrix. So I hope you have understood the logic which I have demonstrated 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 sanjaygupta underscore tech school. You can download my programming app Techimus which is available on Google Play. Thank you for watching this video.