#include<iostream.h>
#include<conio.h>
int sod(int a[10][10],int r,int c)
{
int i,j,sum=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j||i+j==r-1)
sum+=a[i][j];
}
}
return(sum);
}
void main()
{
clrscr();
int a[10][10],r,c,i,j;
cout<<"\n";
cout<<"enter size of row and column ";
cout<<"\n";
cin>>r>>c;
cout<<"\n";
cout<<"enter elements";
for(i=0;i<r;i++)
{
cout<<"\n";
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<"\n";
cout<<"sum is"<< sod(a,r,c);
getch();
}
#include<conio.h>
int sod(int a[10][10],int r,int c)
{
int i,j,sum=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i==j||i+j==r-1)
sum+=a[i][j];
}
}
return(sum);
}
void main()
{
clrscr();
int a[10][10],r,c,i,j;
cout<<"\n";
cout<<"enter size of row and column ";
cout<<"\n";
cin>>r>>c;
cout<<"\n";
cout<<"enter elements";
for(i=0;i<r;i++)
{
cout<<"\n";
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<"\n";
cout<<"sum is"<< sod(a,r,c);
getch();
}