#include <iostream.h>
void main()
{
int A[10][10],i,j,r[10],c[10],row,col;
// Input of no of rows and columns
cout << "Enter no of rows and columns:\n";
cin >> row >> col;
// Input of matrix
cout << "Enter matrix elements:\n";
for( i=0; i<row; i++ )
{ for ( j=0; j<col; j++ )
cin >> A[i][j];
}
// Loop for Row Sum
for( i=0; i<row; i++ )
{
r[i]=0;
for( j=0; j<col; j++ )
r[i] = r[i] + A[i][j];
}
// Loop for Column sum
for ( j=0; j<col; j++ )
{
c[j]=0;
for ( i=0; i<row; i++ )
c[j] = c[j] + A[i][j];
}
} // End of void main
Screenshots:
void main()
{
int A[10][10],i,j,r[10],c[10],row,col;
// Input of no of rows and columns
cout << "Enter no of rows and columns:\n";
cin >> row >> col;
// Input of matrix
cout << "Enter matrix elements:\n";
for( i=0; i<row; i++ )
{ for ( j=0; j<col; j++ )
cin >> A[i][j];
}
// Loop for Row Sum
for( i=0; i<row; i++ )
{
r[i]=0;
for( j=0; j<col; j++ )
r[i] = r[i] + A[i][j];
}
// Loop for Column sum
for ( j=0; j<col; j++ )
{
c[j]=0;
for ( i=0; i<row; i++ )
c[j] = c[j] + A[i][j];
}
} // End of void main
Screenshots: