answersLogoWhite

0


Best Answer

#include #include int main() { clrscr(); int A[10][10],m,n,x,y,sum=0; //Create a Matrix A cout << "Enter number of rows and columns in Matrix A : \n"; cin>>n>>m; cout << "Enter elements of Matrix A : \n"; for(x=1;x cin>>A[x][y]; //Find sum of each row for(x=1;xch column for(y=1;y cout << "\nMatrix A, Row Sum (Last Column)" << " and Column Sum (Last Row) : \n"; for(x=1;x cout << A[x][y] << " "; cout << "\n"; } //Print sum of each column x=n+1; for(y=1;y cout << A[x][y] << " "; cout << "\n"; if(m==n) { for(x=1;x cout << "Sum of diagonal elements is : " << sum << endl; getch(); return 0; }

This program takes in the number of rows (n) and columns (m) as well as the elements as a screen input in a matrix n x m.

It then calculates the sum of each row and each column and outputs it using the 'cout' command.

Also, if it is a square matrix, it calculates the sum of diagonal elements and prints it out.

Click here for SAMPLE INPUT 3 3 9 8 7 6 5 4 3 2 1

Click here for SAMPLE OUTPUT Matrix A, Row Sum(Last Column) and Column Sum(Last Row) : 9 8 7 24 6 5 4 15 3 2 1 6 18 15 12 Sum of diagonal elements is : 15

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a C program to find row sum and column sum of a given matrix?
Write your answer...
Submit
Still have questions?
magnify glass
imp