Разделение массива поровну в C - PullRequest
0 голосов
/ 20 мая 2011

Я пишу C в Linux, разветвляется родитель и N детей.родитель берет sqrt (ArraySize), а остальное делится поровну на N дочерних элементов.

как я могу разделить остальную часть массива поровну на N дочерних элементов? \

Thnx заранее:)

Ответы [ 2 ]

3 голосов
/ 20 мая 2011
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
1 голос
/ 20 мая 2011

Вы не говорите нам достаточно, чтобы дать полный ответ

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

На какой бит вы застряли?

...