There is an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to multiplication of all the elements of A[N] except A[i]. For example Output[0] will be multiplication of A[1] to A[N-1] and Output[1] will be multiplication of A[0] and from A[2] to A[N-1].
Solve it without division operator and in O(n).
How can this problem be solved using c++?
Please discuss the approach
hahaha, my guess is that your teacher wants to avoid a solution in which you'd multiply all elements of A and then put in output[i] that product divided by A[i].
I'd make a function that takes A[], Output[] and i as arguments. I'd initialize Output[i] to one. Then I'd make a for loop with j taking values from 0 to i-1 and set Output[i] to Output[i]*A[j]. Then I'd make another for loop with j taking values form i+1 to N-1 and again set Output[i] to Output[i]*A[j].
Then, I'd call this function for every i from 0 to N-1.