#include <iostream>
usingnamespace std;
int show(int y, int sh[999][999])
{
int b=y-1; int a= b/2;
cout<<"The elements of middle row are :\n";
for(int i=0; i<y; i++)
{
cout<<sh[a][i]<<", ";
}
cout<<endl<<"The elements of the middle column are :\n";
for(int j=0; j<y; j++)
{
cout<<sh[j][a]<<", ";
}
}
int main()
{
int x; int ele[999][999];
cout<<"Enter the size of the matrix [It should be an odd no.] : ";
cin>>x; cout<<endl;
cout<<"Enter the elements.\n";
for(int p=0; p<x; p++)
{
cout<<"Row "<<p+1<<" :\n";
for(int q=0; q<x; q++)
{
cout<<"Column "<<q+1<<" : "; cin>>ele[p][q]; cout<<endl;
}
}
show(x, ele); return 0;
}
This program runs on both i.e. online as well as codeblocks.
#include <iostream>
usingnamespace std;
int show(int y, int **sh)
{
int b=y-1; int a= b/2;
cout<<"The elements of middle row are :\n";
for(int i=0; i<y; i++)
{
cout<<sh[a][i]<<", ";
}
cout<<endl<<"The elements of the middle column are :\n";
for(int j=0; j<y; j++)
{
cout<<sh[j][a]<<", ";
}
}
int main()
{
int x;
cout<<"Enter the size of the matrix [It should be an odd no.] : ";
cin>>x; cout<<endl;
int **ele = newint*[x];
for (int i = 0; i < x; i++)
{
ele[i] = newint[x];
}
cout<<"Enter the elements.\n";
for(int p=0; p<x; p++)
{
cout<<"Row "<<p+1<<" :\n";
for(int q=0; q<x; q++)
{
cout<<"Column "<<q+1<<" : "; cin>>ele[p][q]; cout<<endl;
}
cout<<endl;
}
show(x, ele); return 0;
}
In the first program, you are trying to allocate at least 4MB on the stack, which is a decent amount. Your OS might not be allowing your program to do that.