[Assuming the 2D Array to be a square matrix with odd dimension i.e 2x3, 5x5, 7x7 etc....].
Example, If the array contents is
2 5 4
7 6 9
2 1 8
Output through the program should be:
Middle Row: 7 6 9
Middle Column: 5 6 1
#include<iostream>
using namespace std;
{ cout<<"[moznum.blogspot.com]"<<endl<<endl;
int size;
cout<<"Enter the order matrix ( Order Shoud B in Odd Demension) : ";
cin>>size;
int A[size][size];
for(int i=0;i<size;i++) //taking input
{
for(int j=0;j<size;j++)
{
cout<<"Enter the "<< i+1<<j+1 <<" value of Matrix : ";
cin>>A[i][j];
}
}
cout<<"Middle Row is: "; // printing the mid row
for (int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if (i== size/2)
cout<<A[i][j]<<"\t";
}
}
cout<<"\nMiddle Column is:"; // printing the mid col
for (int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(j==size/2)
cout<<A[i][j]<<"\t";
}
}
}
You Can also Search This topic by this:
didnt get the output because i couldnt key in the value for every row and col :(
ReplyDeleteHlo
ReplyDeletequiet usefull
ReplyDelete