title: How to sort 2d array column wise and row wise for given columns and rows by users
body: <p>guys, this is my first time in stackoverflow
  I want to sort array of random numbers row wise and column wise
  after this I have to search for a given key but I am stocked in
  the first part.
  the problem is user should choose  dimension of array between (2-5000) and elements in array is between (4-25 milion) and each element can be from 0 until int MAX and number of column and row is equal to each other
  I found good code but I did not understand how to change it in order to satisfy the limit of my programm I tried to #define my 2d array like this</p>
  <h1>define R 5000</h1>
  <h1>define C 5000</h1>
  <p>but it is wrong
  this is the code I am trying to write</p>
  <pre><code>#include&lt;stdio.h&gt;
  #define R 500
  #define C 500
  
  void sort_rows(int *arr,int n)
  {
      int i;
      for(i=1;i&lt;n;i++)
      {
          int key=arr[i];
          int j=i-1;
          while(j&gt;=0 &amp;&amp; key&lt;arr[j])
          {
              arr[j+1]=arr[j];
              j--;
          }
          arr[j+1]=key;
      }
  }
  void sort_column(int arr[500][500],int c)
  {
      int key,k;
      int i,j;
      for(i=0;i&lt;c;i++)
      {
          for(j=1;j&lt;c;j++)
          {
              key=arr[j][i];
              k=j-1;
              while(k&gt;=0 &amp;&amp; arr[k][i]&gt;key)
              {
                  arr[k+1][i]=arr[k][i];
                  k--;
              }
              arr[k+1][i]=key;
          }
      }
  }
  int main()
  {
      int arr[R][C];
      int r,c;
      int i,j,size_row,size_column;
      printf(&quot;Enter Number of rows and columns(2-5000)&quot;);
      scanf(&quot;%d%d&quot;,&amp;r,&amp;c);
      for(i=0;i&lt;r;i++)
      {
          for(j=0;j&lt;c;j++)
              arr[i][j]=rand()%(r*c)+1;
      }
      printf(&quot;Original array:\n&quot;);
      for(i=0;i&lt;r;i++)
      {
          for(j=0;j&lt;c;j++)
          {
              printf(&quot;%d &quot;,arr[i][j]);
  
          }
          printf(&quot;\n&quot;);
      }
      size_row=((sizeof(arr)/sizeof(arr[0][0])/(sizeof(arr[0])/sizeof(arr[0][0]))));
      printf(&quot;%d&quot;,size_row);
          for(i=0;i&lt;size_row;i++)
      {
          sort_rows(arr[i],sizeof(arr[i])/sizeof(arr[i][0]));
      }
          size_column=sizeof(arr)/sizeof(arr[0]);
      for(i=0;i&lt;size_column;i++)
      {
          sort_column(arr,size_column);
      }
      printf(&quot;Sorted Array:\n&quot;);
      for(i=0;i&lt;r;i++)
      {
          for(j=0;j&lt;c;j++)
          {
              printf(&quot;%d &quot;,arr[i][j]);
  
          }
          printf(&quot;\n&quot;);
      }
  }
  </code></pre>
  <p>any help would be great</p>