samedi 22 avril 2017

what extra codes should i add to my coding?

srand(time(NULL));
char name[10][100] = {
  "ali",
  "abu",
  "kamil",
  "sarah",
  "siti",
  "aina",
  "ain",
  "hafiz",
  "sofea",
  "amil"
};
int c, n;

for (c = 1; c <= 5; c++) {

  n = rand() % (10 - 1) + 1;
  printf("%s\n", name[n]);

}

return 0;
}

whenever i run it, there are 2 name that came out the same. my lecturer said that i need to add an extra code to avoid redundant random number but idk how. I already tried it.




Aucun commentaire:

Enregistrer un commentaire