Dividindo um array igualmente em C
Pergunta
estou escrevendo um C no Linux, bifurca um pai e N filhos.o Pai pega o sqrt(ArraySize) e o restante é dividido igualmente entre os N filhos.
como eu poderia dividir o resto do array igualmente entre os N filhos?
Obrigado antecipadamente :)
Solução
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
Outras dicas
Você não está nos dizendo o suficiente para dar uma resposta completa
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
Em que parte você está preso?
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow