Hi, I need some help with my code.
My assignment is to
Write a C program that finds thesum of the diagonal elements of a matrix. Specifically, the programshould first prompt the user to input the number of rows and columnsof the matrix, then prompt the user to input its elements, then printthe matrix the user entered and finally print the sum of the diagonalelements. You can assume that the maximum number ofrows and columns the user inputs is 10, that the number of rows andcolumns the user enters are always equal, and the elements of thematrix to be integer numbers.
Implementation Requirements:
- Implement a function called “findDiagSum” to find the sum of the diagonal elements. The function should return the sum of the diagonal elements (which would be an integer number). Define the function prototype appropriately in your program. (Carefully think over the arguments of the function)
2. Implement a function called “print_matrix”, whose prototype is—
“voidprint_matrix(int mat[10][10], int r, int c);”
Define the functionprototype in your program.
I am not sure how to call the void print_matrix function into the main function. If somebody could help me with this and also give me some insight to make sure my whole code looks good. Thanks for all your help in advance.Code:void print_matrix(int mat[10][10], int r, int c); int findDiagSum(); void main() { int mat[10][10], r, c, i, j, ssum; ssum = findDiagSum(); printf("The sum of the diagonal elements is &ssum"); } void print_matrix(int mat[10][10], int r, int c) { int i, j; printf("\nEnter the rows and columns of the matrix: "); scanf("%d %d", &r, &c); printf("\nEnter the elements of the matrix: "); for(i=0; i<r; i++) for(j=0; j<c; j++) scanf("%d", &mat[i][j]); printf("\nThe matrix is\n"); } int findDiagSum() { int mat[10][10], r, c, i, j, sum=0; for(i=0; i<r; i++) for(j=0; j<c; j++) { if (i==j) sum = sum + mat[i][j]; } return sum; }