title: Fill a defined 2D Array with random numbers in C / Average / Max Value
body: <p>I've created this 2D 21x21 array that has all it's values set to -1. I wrote it to print the address and value and somehow it only starts at [6][19] why?</p>
  
  <p>What i want to do is to replace some of the -1 values with random numbers from 0 to 100 in the same array. I know i need to seed it with srand but i'm having problems connecting the functions since i'm a total beginner in C.</p>
  
  <p>EDIT 1:</p>
  
  <p>Now i can print the whole array and fill it with random numbers. For the -1 values i just assigned directly which for this case its fine.</p>
  
  <p>What i'm trying now is finding the average of all the values and the maximum number, so what i have is:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt; 
  
  
  int main()
  {
  
  int a[21][21], i , j;
  
  for (i = 0; i &lt; 21; i++)
  {
      for ( j = 0; j &lt; 21; j++)
      {
          a[i][j] = GetRand(0, 100);
          a[7][15] = -1;
          a[10][6] = -1;
          a[13][5] = -1;
          a[15][17] = -1;
          a[17][17] = -1;
          a[19][6] = -1;
          printf("%3d" , a[i][j]);
      }
      printf("\n");
  }
  return 0;
  }
  
  
  
  // random seed
  int GetRand(int min, int max);
  int get() {
   int i, r;
  for (i = 0; i &lt; 21; i++)
   {
  r = GetRand(0, 100);
  printf("Your number is %d \n", r);
   }
   return(0);
   }
  
  int GetRand(int min, int max)
  {
  static int Init = 0;
  int rc;
  
  if (Init == 0)
  {
  srand(time(NULL));
  Init = 1;
  }
  
  rc = (rand() % (max - min +1) +min);
  
  return (rc);
  }
  
  
  
  // average
  
  int avg()
  
  float sum=0.0;
  
  for(i = 0; i &lt;= 21; i = i + 1) {
  
  
      for(j = 0; j &lt;= 21; j = j + 1){
  
  
           sum = sum + a[21][21];
       }
  
  printf("The the average number is %.2f\n", sum/21);
  }
  
  
  
  
   //find maximum of all values    
  
   int *pv = &amp;a[0][0];
   max = min = 0;
   for (i = 1; i &lt; i*j; ++i){
      if (pv[i] &gt; pv[max])
          max =i;
      if (pv[i] &lt; pv[min])
          min = i;
  }
  printf("The max value is %d in row %d, col %d\n", pv[max], max/j, max%j);
  
  
  return 0;
  }
  </code></pre>
  
  <p>For the average function the compiler tells me that expected a declaration before i, which is "float sum=0.0;" but i haven't been able to fix that yet.</p>
  
  <p>For the finding the max function i'm not sure yet what i'm doing there, i just have a vague idea of how it's done...am i going in the right direction?</p>
  
  <p>Thanks!</p>