Iam trying to find sum of diagonals for every sub matrix in matrix by using c. Can anyone please help me
Thanks,
Santosh.
Iam trying to find sum of diagonals for every sub matrix in matrix by using c. Can anyone please help me
Thanks,
Santosh.
Hi,
First you could try to use for loop to iterate every cell present in the matrix. Conditions inside the for loops ((rows < i) and (columns < j)) will ensure the program compiler, not to exceed the Matrix limit. Otherwise, the matrix will overflow. And we could use the scanf statement inside the for loop will store the user entered values in every individual array element.
In the next for loop, we could find sum of diagonal elements of a matrix.
Here is my code:
for(rows = 0; rows < i; rows++)
{
for(columns = 0;columns < j;columns++)
{
scanf("%d", &a[rows][columns]);
}
}
for(rows = 0; rows < i; rows++)
{
Sum = Sum + a[rows][rows];
}
printf("\n The Sum of Diagonal Elements of a Matrix = %d", Sum );
Best Regards,
Jeanine
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
This forum is only for Question and Answer not for any home work or assignment .
Thanks
3 people are following this question.