C++ Program to show Diagonal element of 2-Dimensional Array.

Spread the love..

#include<iostream>
using namespace std;
int main()
{
int a[4][4]={4,5,6,7, //a[0][3]
                  9,2,5,8, //a[1][2]
                  9,2,3,4, //a[2][1]
                  1,2,3,4}; //a[3][0]
int i,j,t;
cout<<"\nDiagonal elements are:=";
for(i=0;i<4;i++)
{
      for(j=0;j<4;j++)
      {
           if(i+j==3)
           cout<<endl<<a[i][j];
      }
}
return 0;
}

Spread the love..

Leave a Reply

Your email address will not be published. Required fields are marked *