Answer to Question #212116 in C for sai

Question #212116

write a program that accepts an MxN matrix then do the following:

Find the sum of the main and opposite diagonal elements of an MxN matrix and adds the main diagonal of the matrix as well as the opposite diagonal of the matrix


1
Expert's answer
2021-06-30T03:15:43-0400
#include <stdio.h>
#define SIZE 3 


int main()
{
    int Arr[SIZE][SIZE];
    int r, c;
    int sum = 0;
    printf("Enter elements in matrix of size %dx%d: \n",SIZE,SIZE);
    for(r=0; r<SIZE; r++)
    {
        for(c=0; c<SIZE; c++)
        {
            scanf("%d", &Arr[r][c]);
        }
    }
    for(r=0; r<SIZE; r++)
    {
        for(c=0; c<SIZE; c++)
        {
            if(r+c == ((SIZE+1)-2))
            {
                sum += Arr[r][c];
            }
        }
    }


    printf("\nSum of minor diagonal elements = %d", sum);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS