Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

Write a program that reads an NxN square matrix M that calculates the sum of the elements in individual rows, individual columns and the two main diagonals. Among these sums, print the largest. Consider the following matrix of order 3x3: 1 10 13 2 14 12 3 9 8 The row sum values are 1+10+13=24, 2+14+12=28 and 3+9+8=20. The column sum values are 1+2+3=6, 10+14+9=33 and 13+12+8=33. The diagonal sums are 1+14+8=23 and 13+14+3=30. The expected output is maximum among these sums, which is 33. INPUT: First line contains a value N representing the dimension of the input matrix M, followed by N

OpenStudy (anonymous):

i think u want it in c.

OpenStudy (anonymous):

#include<stdio.h> //Main Function int main() { int n,a[101][101],i,j; int max=0,sum=0; scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } j=0; //COLOUMN SUM while(j<n) { sum=0; for(i=0;i<n;i++) sum+=a[i][j]; if(sum>max) max=sum; j++; } i=0; //ROW SUM while(i<n) { sum=0; for(j=0;j<n;j++) sum+=a[i][j]; i++; if(sum>max) max=sum; } //DIAGONAL SUM the main problem sum=0; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i==j) sum+=a[i][j]; } } if(sum>max) max=sum; sum=0; for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i+j==n-1) sum+=a[i][j]; } } if(sum>max) max=sum; printf("%d",max); return 0; }

OpenStudy (anonymous):

#include<iostream> //AUTHOR: ALBOCODER using namespace std; int row(w) { int k=0; for (int e=0; e<w; e++) { k+=matrix(w,e); } return k; } int column(w) {int k=0; for (int e=0; e<w; e++) { k+=matrix(e,w); } return k; } int diag(w) { int k=0; for (int e=0; e<w; e++) { k+=matrix(e,e); } return k; } int rdiag(w) { int k=0; for (int e=w-1; e>=0; e--) { k+=matrix(e,e); } return k; } int main() { /* Here you can write the function to enter the matrix */ int N, temp=-999999; cin >> N; for (int a=0; a<N; a++) { if (temp>=row(N)) temp= row (N); if (temp>=column(N)) temp= column(N); if (temp>=diag(N)) temp= diag(N); if (temp>=rdiag(N)) temp= rdiag(N); } cout << temp; return 0; }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!