mercredi 8 juillet 2020

Is this the right approach to add an element to an array?

I have an array.

int Game[100];

I want to make a random sequence of two numbers inside this array. ( 0 and 1 ).

int i;
int Game[];
for(i = 100; i >= pos; i--) {
       // Random number ( 0 or 1 )
       int v = (int)rand() / (int)RAND_MAX;
       Game[i] = Game[i-1];
       Game[i] = v;
}

Is this the right approach?




Aucun commentaire:

Enregistrer un commentaire