It can be done using one extra array only that is the output array out[] *int out = (int *)malloc(sizeof(n)); //n is the number of elements in a int i,temp = 1; for(i=0;i<n;i++) { out[i] = temp; temp*=a[i]; } temp =1; for(i=n-1;i>=0;i--) { out[i] *= temp; temp*=a[i]; }*
On Sun, Jul 17, 2011 at 4:43 PM, manish patel <manispatel...@gmail.com>wrote: > thanx!!!! the question was asked by MS today in MNNIT. > > On Sun, Jul 17, 2011 at 4:35 PM, Anurag Aggarwal < > anurag19aggar...@gmail.com> wrote: > >> take two extra arrays b[] and c[] >> in b[] store the following thing >> b[0]=1; >> b[i]=b[i-1]*a[i-1]; >> >> >> in c[] store following things >> c[n-1]=1; >> c[i]=c[i+1]*a[i+1] (i>n-1) >> fill the c[] array in reverse order i.e. start from n-1 then go to 0; >> >> now output[] would be >> output[i]=b[i]*c[i]; >> >> >> >> >> On Sun, Jul 17, 2011 at 4:28 PM, geek forgeek <geekhori...@gmail.com>wrote: >> >>> given an array a[0......n-1] .required to find the output array out >>> [0.........n-1] such that out [i] is the product of all the numbers a[0] to >>> a[n-1] excluding a[i] >>> for ex out[2]=a[0]*a[1]*a[3]*a[4]....a[n-1] >>> constraint is not using division operator >>> >>> how to do this in O(n)?? >>> >>> -- >>> 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. >>> >> >> >> Anurag Aggarwal >> >> -- >> 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. >> > > > > -- > With Regards > > Manish Patel > BTech 2nd Year > Computer Science And Engineering > National Institute of Technology -Allahabad > > > -- > 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. > -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * <https://www.facebook.com/profile.php?id=100000655377926> "NEVER SAY NEVER" * -- 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.