Разделить массив одинаково в C
Вопрос
Я пишу C в Linux, вилки родитель и н дети.Родитель принимает SQRT (Arraysize), а остальное разделено одинаково на 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
.
Какой бит вы застряли?
Не связан с StackOverflow