Wednesday, September 3, 2008

C program to find column sum of matrix

#include < iostream.h >
#include < conio.h >
void sum(int a[][20],int row, int col)
{
int colsum[10],i,j;
for(i=0;i< col;i++){
colsum[i]=0;
for(j=0;j< row;j++){
colsum[i]=a[j][i]+colsum[i] ;
}}
cout<< "\nTHE SUM OF THE COLOUMN" << endl;
for(i=0;i< row;i++){
cout << "SUM OF THE ELEMENTS OF THE COLOUMN "<< i+1<< "="<< colsum[i]<< endl;
}
}
void main(){
clrscr();
int colsum[10],i,j,row,col,a[20][20];
cout<< "ENTER THE NUMBERS OF ROWS AND COLOUMN"<cin>> row>> col;
cout<< "ENTER THE ELEMENTS INTO THE MATRIX"<< endl;
for(i=0;i< row;i++){
for(j=0;j< col;j++){
cin>> a[i][j];
}}
cout<< "THE MATRIX IS"<< endl;
for(i=0;i< row;i++){
cout<< endl;
for(j=0;j< col;j++){
cout<< a [i][j]<< "\t";
}}
sum(a,row,col);
getch();
}

0 comments: