My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to find the sum of diagonal elements of the matrix

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int x[10][10],m,n,sum=0;
 cout<<"number of rows and columns"<<endl;
 cin>>m>>n;
 for(int i=0;i<m;i++)
  for(int j=0;j<n;j++)
  {
   cin>>x[i][j];
   if(i==j)
   sum+=x[i][j];
   }
  cout<<"sum of diagonal elements: ";
  cout<<sum;
  getch();
  }

0 comments: