我在Linux中编写C,伪造父母和n个孩子。父母父母采用SQRT(数组),其余部分平均划分为N个孩子。

如何将剩余的阵列划分为n个孩子?\

thnx提前:)

有帮助吗?

解决方案

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
.

其他提示

你真的不告诉我们足以给出一个完整的答案

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
.

你被困在哪一点?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top