#include <stdio.h>
int main()
{
int n = 7;
int a[] = {0, -10, -12, 19, 20, -1, -2};
int max;
int small;
int co;
int pro = 1;
int i;
i = 0;
while(i < n)
{
while(i < n && a[i] == 0)
i++;
max = 1;
co = 0;
small = 2147483647;
while(i < n && a[i] != 0)
{
if(a[i] < 0)
{
co++;
if(small > (-a[i]))
small = -a[i];
}
max *= a[i];
i++;
}
if(co & 1)
max = (-max) / small;
if(pro < max)
pro = max;
}
printf("%d ",pro);
return 0;
}
On Wed, Jul 13, 2011 at 10:52 AM, kranthi kumar <[email protected]>wrote:
> I think this is the solution what u need.... U can do in O(n) time...
>
>
>> #include<iostream>
>>> using namespace std;
>>>
>>> main()
>>> {
>>> int a[7] = { 0, 0, 0, 19, 380, -1, 2};
>>> int prod, nprod;
>>> bool x = false;
>>>
>>> for(int i=0;i<6;i++)
>>> {
>>> nprod = a[i] * a[i+1];
>>> cout<<nprod<<endl;
>>> if( x == false)
>>> {
>>> x = true;
>>> prod = nprod;
>>> }
>>> else if( x== true && prod < nprod )
>>> prod = nprod;
>>> }
>>>
>>> cout<<"\nResult: "<<prod;
>>> }
>>>
>>
>>
> --
> Regards:
> -----------------------
> D Kranthi kumar
> Computer Science & Engg.
> 1st Mtech, IIT Madras.
>
> --
> 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.
>
--
Varun Pahwa
B.Tech (IT)
7th Sem.
Indian Institute of Information Technology Allahabad.
Ph : 09793899112
Official Email :: [email protected]
Another Email :: [email protected]
People who fail to plan are those who plan to fail.
--
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.