How to put random number in int array C -


i pass random number generate int array. not right.

thanks in advance,

#include <stdio.h> #include <stdlib.h> #include <time.h>  int main() {    int i, n;    time_t t;     n = 5;     int haystack [n];       /* intializes random number generator */    srand((unsigned) time(&t));     /* print 5 random numbers 0 50 */    for( = 0 ; < n ; i++ )     {       printf("%d\n", rand() % 50);       haystack[i] = rand();       printf("%d\n", haystack[i]);     }     return(0); } 

this prints random numbers < 50: printf("%d\n", rand() % 50);

this generate new random numbers no such limitation: haystack[i] = rand();

there no reason them equal.

i guess want like:

haystack[i] = rand() % 50; printf("%d", haystack[i]) 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -