```
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
int A[10][10],m,n,x,y,sum=0;
//Create a Matrix
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<n+1;++x)
for(y=1;y<m+1;++y)
cin>>A[x][y];
//Find sum of each row
for(x=1;x<n+1;++x)
{
A[x][m+1]=0;
for(y=1;y<m+1;++y)
A[x][m+1]=A[x][m+1]+A[x][y];
}
//Find sum of each column
for(y=1;y<m+1;++y)
{
A[n+1][y]=0;
for(x=1;x<n+1;++x)
A[n+1][y]+=A[x][y];
}
cout << "\nMatrix A, Row Sum (Last Column)" << " and Column Sum (Last Row) : \n";
for(x=1;x<n+1;++x)
{
for(y=1;y<m+2;++y)
cout << A[x][y] << " ";
cout << "\n";
}
//Print sum of each column
x=n+1;
for(y=1;y<m+1;++y)
cout << A[x][y] << " ";
cout << "\n";
if(m==n)
{
for(x=1;x<m+1;x++)
for(y=1;y<n+1;y++)
if(x==y)
sum+=A[x][y];
else
if(y==m-(x+1))
sum+=A[x][y];
}
cout << "Sum of diagonal elements is : " << sum << endl;
getch();
return 0;
}
```

## Recommended Answers

Jump to PostHey,

I'll give you an example.. Then you can just relevant insert the code where you need it.

`int choice = 0; cout << "Please enter an option: \n"; cout << "\t\t 1) Sum Row\n"; cout << "\t\t 2) Sum Column\n"; cout << "\t\t 3) Diagonal Sum\n"; …`

Jump to PostApologies.

I purposly left out main, so, you need to include main..

`int main() { }`

As you had it before, just implement my code. :)

Kinda like this (NOT COMPLETE):

`#include <iostream> using namespace std; int main() { int choice = 0; …`

## All 6 Replies

diknas
0
Newbie Poster

phorce
131
Posting Whiz in Training
Featured Poster

diknas
0
Newbie Poster

phorce
131
Posting Whiz in Training
Featured Poster

diknas
0
Newbie Poster

phorce
131
Posting Whiz in Training
Featured Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.