Your solution to 1 works fine. I hope you get the job. But it needs O(N) additional storage for the stack. You can also do with constant additional storage.
#include <stdio.h> int main(void) { #define N (sizeof a / sizeof a[0]) int a[] = {7, 9, 4, 8, 2}; int result[N], i, product; for (i = 0, product = 1; i < N; product *= a[i++]) result[i] = product; for (i = N - 1, product = 1; i >= 0; product *= a[i--]) result[i] *= product; for (i = 0; i < N; i++) printf("%d ", result[i]); printf("\n"); return 0; } On Aug 3, 7:08 am, Poised~ <dip10c...@gmail.com> wrote: > I am not looking for answer. Just sharing these Section 2 questions: > > 1. Given an array arr[] of n integers, construct a Product Array prod[] (of > same size) such that prod[i] is equal to the product of all the elements of > arr[] except arr[i]. Solve it without division operator. Give an efficient > code. > (if you are interested, here is my solution:http://ideone.com/EaTUF, > developed at the test time itself). -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.