#include <iostream>

using namespace std;

int main()
{
   int input[10];
    int n;
   cout<<"enter n"<<endl;
   cin>>n;
   int output[10];
   cout<<"enter input array"<<endl;
   for(int i=0;i<n;i++)
   cin>>input[i];

   int a[n],b[n];
   a[0]=1;
   for(int i=1;i<n;i++)
   {
       a[i]=a[i-1]*input[i-1];

   }
   b[n-1]=1;
   for(int i=n-2;i>=0;i--)
   {
       b[i]=b[i+1]*input[i+1];
   }
   for(int i=0;i<n;i++)
   {

       output[i]=a[i]*b[i];
       cout<<output[i]<<endl;
   }
   return 0;
}











On Sun, Jun 26, 2011 at 9:38 PM, ross <jagadish1...@gmail.com> wrote:

> Given an array A , of N integers ( In no particular order), fill up an
> auxilary array B such that B[i] contains the product of
> all elements in A other than A[i].
> Constraints:
> O(n) Time,
> Can this be done with O(1) space?
> Division is *not* allowed .
>
> eg: A 1 2 3 4 5
>  B     120 60 40 30 24
>
> --
> 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.
>
>

-- 
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.

Reply via email to