Piet Souris wrote:
Campbell Ritchie wrote:Obviously that won't work at all well if any of the array elements is 0.
And what then? . . .
You can fill the resultant array with 0s and if there is only one 0 in the original array, calculate the product of all the other elements, only for that one element. If there are multiple 0s in the original array, every result will reduce to 0. I am sure OP already knows what happens if you don't compensate for 0s.
You will also get incorrect results if you suffer an arithmetic overflow calculating the product.