 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can search whether a particular element is present in matrix or not 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 Techimus which is available on Google Play. Now coming on to the topic, for this problem I am going to implement a code with the help of C programming so that you can understand how we can pass a 2D array into function so that we can search whether a particular element is available in it or not. So for that purpose I have included a header file stdio.h. Now I am declaring a function whose name is search. This written type is void. It will receive two arguments. First one is 2D array of integer type and second one is only integer variable. So this statement will be known as function declaration. Now I am implementing main function. Inside main function I am declaring a 2D array then variable ij and n. Now with the help of printf I am going to display the message enter elements on console to receive elements from user. I am implementing nested loops. So with these nested loops I will be repeating scanf statement so that I can read elements from user. So all the entered elements will be stored inside a matrix at different indexes. Now after reading all the elements of 2D array I have to read that element which I want to search in the matrix. So the message will be enter the number you want to search in matrix. Now I can read that number using scanf and that number will be stored inside n variable. So after reading both entities first one is matrix and second one is the number that I want to search in the matrix. Now I am calling the search function where I am passing array n variable n. So this statement will be known as function calling. After calling I am writing the statement return 0. So this is the complete definition of main function. After defining main function I have to implement the definition of search function where I am receiving first argument in form of 2D array and second argument in form of a variable that is n. So this block will be known as function definition. Inside this function definition first I am declaring two variables i and j then a flag variable which is initially 0. Now for calculation purpose or to apply logic I am implementing nested loops. So here first loop is controlled by i variable and second loop is controlled by j variable. So i will be providing row indexes and j will be providing column indexes. Now I have to compare aij with variable n. So if array element that is stored at aij index if it is equals to n then we can say n means that number that we want to search is available inside 2D array or matrix. So I am assigning one in f variable and if number is available in the matrix then I can break these loops so that unnecessarily these loops will not be repeated. So after completion of these loops I have to check whether the value of f is one or if it is sorry whether the value of f is one or it is zero. So if number is available in matrix then only f will become one otherwise f will remain zero. So I am checking if f double equals to one then I can print number is present in matrix else I can print number is not present in matrix. So this way I have implemented the complete code in front of you. So total two functions are defined first one is main which is reading 2D array and the number which we want to search then main function is called search function then you can see the definition of search which is comparing the n variable with aij. So if n is available inside aij then value of f variable will become one and loop will be terminated using break and if number is not available in a matrix then f will remain zero. So after completion of loop I have checked the value of f if it is one then number is available otherwise not. Now I am executing this code so I am entering numbers now you can see it is asking for the number which we want to search so I am entering five. Now see the result number is present in matrix. Now again I am executing this code I am entering same values in matrix but this time I want to search 10 you can see the message number is not present in matrix. So the program is working correctly in both the ways if number is available or not available. So I hope you have understood how we can apply a searching operation on 2D array or matrix by passing 2D array into a function. 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 tech school. You can also download my programming app TechMS which is available on google play. Thank you for watching this video.