SUM OF BOTH DIAGONALS

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,s=0,j,r,c,ch,a[50][50];
cout<<“Entr Array Limit”<<endl;
cin>>r>>c;
if(r!=c)
cout<<“Wrong Choice”<<endl;
else
{
cout<<“Enter Array”<<endl;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<“Enter Choice 1:main 2:Secondary”<<endl;
cin>>ch;
switch(ch)
{
case 1:
for(i=0;i<r;i++)
{
s=s+a[i][i];
}
cout<<“Sum = “<<s;
break;

case 2 :
j=c-1;
for(i=0;i<r;i++)
{
s=s+a[i][j–];
}
cout<<“Sum = “<<s;
break;

default :
cout<<“Wrong Choice”<<endl;
break;

}
}
getch();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s