开发者

Dividing an array equally in C

开发者 https://www.devze.com 2023-03-07 00:50 出处:网络
i am writing a C in Linux, forks a parent and N children. the Parent takes the sqrt(ArraySize) and the rest is divided equally upon the N children.

i am writing a C in Linux, forks a parent and N children. the Parent takes the sqrt(ArraySize) and the rest is divided equally upon the N children.

how could i divide the rest of the array equally upon the N children?\

Thnx开发者_Python百科 in advance :)


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


You're not really telling us enough to give a full answer

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

Which bit are you stuck on?

0

精彩评论

暂无评论...
验证码 换一张
取 消