Row and Column sum of matrix

Sum of matrix row and column : 

Program to calculate sum of row and sum of  column of a matrix .

#include<iostream.h>                                                          
#include<conio.h>            
                                                 
void main()                                                                   
{       
                                                                         
      clrscr();                                                                     
      int a[10][10], i,j,r[10], c[10],row,col;        
                             
      cout<<"\n enter the number of rows & columns of matrix:";                 
      cin>>row>>col;      
                                                        
      cout<<"\n enter the elements of a matrix:\n";                       
      for(i=0; i<row; i++)     
                                                        
                 for(j=0; j<col; ++j)
                 cin>>a[i][j];                                                            
                cout<<"\n given matrix is:";      
                                           
                                for(i=0; i<row; ++i)                                                          
                               {                                                                               
                                             cout<<"\n";                                                                   
                                             for(j=0; j<col; ++j)                                                        
                                             cout<<a[i][j]<<" ";                                                       
                               }         
                                                                    
                               for(i=0; i<row; i++)                                                          
                              { 
                                             r[i]=0;                                                                       
                                             for(j=0;j<col;++j)                                                                 
                                             r[i]+=a[i][j];                                                      
                              }    
                                                                        
                               for(j=0; j<col; ++j)                                                          
                               {                                                                               
                                             c[j]=0;                                                                     
                                            for(i=0; i<row; ++i)                                                           
                                            c[j]+=a[i][j];                                                          
                               }        
                                                                    
         for(i=0; i<row; ++i)                                                            
        cout<<"\n sum of row#"<<i+1<<"is:"<<r[i];                                 

        for(i=0; i<col; ++i)                                                             
        cout<<"\n sum of column#"<<i+1<<"is:"<<c[i];     
                         
        getch();                                                                   
}                                                  

Post a Comment

0 Comments