Matrix - Sum of Minor Diagonal
Coding Problem Keys
Matrix - Sum of Minor Diagonal
Problem Statement
Maria, class teacher of standard twelve has set out on a vacation to Coorg. They have booked accommodation in a resort and the resort authorities organize Campfires every night as a part of their daily activities. But she can't take all the students of her class on vacation. So she planned to keep a test, those who score full marks on the test are eligible to go on a vacation. The test consists of a single question based on a 2D array, Given a square matrix x[5][5], write a code to compute the sum of minor diagonal. Help her to solve this.
Input Format
Output Format
Example Input/Output 1
Input
Output
Explanation
Example Input/Output 2
Input
Output
Note
Solution
Programming Language: C Language
#include <stdio.h> int main(){ int arr[5][5]; int i,j,sum=0; for(i=0;i<5;i++) for(j=0;j<5;j++) scanf("%d",&arr[i][j]); for(i=0;i<5;i++) for(j=0;j<5;j++) if(i+j==4) sum+=arr[i][j]; printf("%d",sum); }
// Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments