0

我正在 Linux 中编写一个 C,分叉一个父级和 N 个子级。Parent 接受 sqrt(ArraySize) ,其余部分平均分配给 N 个孩子。

我怎样才能将数组的其余部分平均分配给 N 个孩子?\

提前谢谢:)

4

2 回答 2

3
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
于 2011-05-20T08:18:52.977 回答
1

您并没有真正告诉我们足够的信息来给出完整的答案

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

你卡在哪一点?

于 2011-05-20T08:14:48.447 回答