#include<iostream>
using namespace std;
int main()
{
int arr[5]={1,2,3,4,5};
int res[5]={1,1,1,1,1};
int left=1,right=1,i=0;
for(i=0;i<5;++i)
{res[i]*=left;
res[4-i]*=right;
left*=arr[i];
right*=arr[4-i];
}for(i=0;i<5;++i)
cout<<res[i]<<endl;
cin.sync();
cin.get();
return 0;
}
On Sun, Jun 6, 2010 at 1:12 AM, Raj N <[email protected]> wrote:
> 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
> and in O(n).
>
> Can someone explain me the logic.
> Thanks!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
yezhu malai vaasa venkataramana Govinda Govinda
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.