 उस्या वो श heraus चच्रे क्ब्ता, संज़े गुप्ता, अगर नाद़ लिए मुश्या से पासे should be shown. how you can calculate some of diagonal elements 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 tech image which is available on google play now I am going to implement the solution of this problem of this problem. So first of all, I am including a header file STDI dot H. Now I'm going to declare a function. That is ском, then ixo its dimension is 3 by 3. So you can see, name of function is sum, its written type is integer and the sum function will receive a 2D array whose dimension is 3 by 3. So this statement is function declaration. now i am defining main function inside main first i am declaring a 2d array then ij variables and then s now with the help of printf the message enter elements will be displayed on console to receive elements from user i am applying nested loops अखाई बाजा उते, वो सिर्जा गातीवगडा और भी क्छ़ानाזה जातीगी रहा होँी ब्चृदा ध्करूँअवा़ कराउगाई जातीगी अखाई्जाई के विर्छाई कें बाजा गातीवगडाई. after receiving the sum, I can display that sum on console with the help of this printf statement and this is the complete definition of main, after that I have to define sum function so this block will be known as function definition inside this function definition I am declaring variables and here S variable is initialized with 0 for additional purpose I am applying nested loops again so first loop I will provide row indexes and J loop will provide column indexes inside this loop I am applying the condition for diagonal so diagonal is framed where row and column indexes are same so the condition is if IW equals to J if I which is representing row index and J which is representing column index both are same then we can add AIJ with S so this way I have implemented the complete logic after completion of these two loops I can return value of S and that return value will be received inside main function and then the sum will be displayed on console this is the complete implementation of the program which is calculating sum of main diagonal available in a matrix now I am executing this code sorry I forgot to use semicolon in line number 16 so I have placed semicolon now again I am executing this code you can see it is asking for elements so I am entering 1, 2, 3, 4, 5, 6, 7, 8, 9 and you can see the sum equals to 15 so diagonal elements are 1, 5 and 9 so 5 plus 1 is 6 plus 9 is 15 so output is printed correctly so the program is working properly now I am going to implement another logic which can calculate sum of diagonal so here I am removing J loop and with only I loop I can calculate the diagonal sum or you can say with single loop I am calculating diagonal sum of a matrix so I have just implemented this code I is 0, I less than 3, I is plus plus and then S equals to S plus AI so here you can see I have used I at both indexes row and column so the main diagonal indexes are 0, 0, 1, 1, 2, 2 so if I am using I here so it will be first A is 0, 0 so A is 0, 0 element will be added to S so value of I will become 1 so A11 will be added into S then similarly A22 will be added into S so this way complete diagonal of the matrix will be added into S variable and the result of S will be returned into main function so this is the second logic through which we can calculate sum of main diagonal using only one loop again I am executing this code I am entering the values you can see the same output is displayed again so friends there are two different ways for calculating main diagonal sum you can use nested loops with IF condition or you can simply use a single loop so that you can directly point the diagonal indexes I hope you have understood both the logics and how you can pass 2D array into function so if you want to watch more programming related videos you can follow or subscribe my youtube channel that is youtube.com slash sanjaygupta underscore tax school you can download my programming app Techimage which is available on google play thank you for watching this video