Question

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 in advance :)

Was it helpful?

Solution

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

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top