在C中平均分组数组

时间:2011-05-20 08:10:39

标签: c linux arrays divide

我在Linux上写一个C,向父母和N个孩子求助。 Parent接受sqrt(ArraySize),其余部分平均分配给N个孩子。

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

Thnx提前:)

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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

你坚持了哪一点?