0% found this document useful (0 votes)
8 views1 page

Matrix Diagonal Sum Calculator

This C++ program defines a 2D array to represent a matrix. It prompts the user to enter the number of rows and then enters values for the matrix. It then calculates the sum of values above the main diagonal, below the diagonal, on the main diagonal, and on the secondary diagonal. Finally, it prints out the results of each summation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Matrix Diagonal Sum Calculator

This C++ program defines a 2D array to represent a matrix. It prompts the user to enter the number of rows and then enters values for the matrix. It then calculates the sum of values above the main diagonal, below the diagonal, on the main diagonal, and on the secondary diagonal. Finally, it prints out the results of each summation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <iostream.

h> void main(void) { int mas[10][10],n=0;int i=0,j=0,sum_above=0,sum_under=0,diogonali=0,vt_diogon=0; cout<<"Vvedite kolicestvo strok v Matrite:"; cin>>n; cout<<"Vvedite samu matritu:"; for (i=1; i<=n; i++) for (j=1; j<=n; j++) { cout<<"["<<i<<"]["<<j<<"]="; cin>>mas[i][j]; } for (i=1; i<=n; i++) for (j=1; j<=n; j++) { if (i<j) sum_above = sum_above + mas[i][j]; //summa cisel nad diogonaliu if (i>j) sum_under = sum_under + mas[i][j]; //summa cisel pod diogonaliu if (i==j) diogonali = diogonali + mas[i][j]; //summa cisel na glavnoi diogonali if (i+j==n+1) vt_diogon = vt_diogon + mas[i][j]; //summa cisel na vtorostip diogonali } cout<<"Summa cisel nad glavnoi deagonaliu ="<<sum_above<<endl; cout<<"Summa cisel pod diogonaliu ="<<sum_under<<endl; cout<<"Summa cisel na glavnoi diogonali ="<<diogonali<<endl; cout<<"Summa cisel na vtorostipennoi diogonali ="<<vt_diogon; }

You might also like