Search code examples
clinuxarraysdivide

Dividing an array equally in C


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


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