lundi 22 mai 2017

How can i put different number in 2 array on C [duplicate]

This question already has an answer here:

I tried to put different random number element in each array. However that 2 arrays got exactly same 10 random number. What's wrong with me and how can I solve this?

#define MAX 100
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


void number(int* array)
{
    srand((long)time(NULL));
    for (int i = 0; i < 20; i++)
        array[i] = rand() % MAX + 1;

}

void printing(int* p_array)
{
    for (int i = 0; i < 20; i++)
        printf(" %d", p_array[i]);
    puts("");
}

int main(void)
{
    int score1[20];
    int score2[20];
    number(score1);
    printing(score1);
    number(score2);
    printing(score2);

    return 0;
}




Aucun commentaire:

Enregistrer un commentaire