Diviser un tableau de manière égale en C
Question
J'écris un C à Linux, fourche un parent et des enfants.Le parent prend le SQRT (fatalité) et le reste est divisé de manière égale sur les N enfants.
Comment pourrais-je diviser le reste de la matrice de manière égale sur les N enfants en N? \
thnx à l'avance :)
La solution
int arraySize = 100; // You would get a count from the array here
int nChildren = 5; // This would be provided by you as a parameter to this function
int parentSize = sqrt(arraySize);
int remainder = arraySize - parentSize;
int nChildSize = (remainder / nChildren) + 1
Autres conseils
Tu ne nous dis pas vraiment assez pour donner une réponse complète
Decide size of share for each child, also determine what to do with any "remainder"
For each child
allocate an array sufficient to hold the required number of value
populate the array
Quel bit êtes-vous coincé?
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow