A program to initialize a 2-D array and display the sum of it's diagonal.

 

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],i,j,b=0;

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"Enter a number: ";
cin>>a[i][j];
}
}

for(i=0;i<3;i++)
b=a[i][i]+b;
cout<<"\nThe sum of diagonal is "<<b;

getch();
}

 

< Back