C++ Program to Inter-change the digit in 2-Dimensional array.

Spread the love..

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

return 0;
}

Spread the love..

Leave a Reply

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