title: How to put random number in int array C
body: <p>I would like to pass a random number i generate to an int array. I get something but its not right.</p>
  
  <p>Thanks in advance,</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  int main()
  {
     int i, n;
     time_t t;
  
     n = 5;
  
     int haystack [n];
  
  
  
     /* Intializes random number generator */
     srand((unsigned) time(&amp;t));
  
     /* Print 5 random numbers from 0 to 50 */
     for( i = 0 ; i &lt; n ; i++ ) 
     {
        printf("%d\n", rand() % 50);
        haystack[i] = rand();
        printf("%d\n", haystack[i]);
  
     }
  
     return(0);
  }
  </code></pre>