Find the maximum product of three numbers in an array?
Eg. 9,5,1,2,3
Max product= 9*5*3= 135
The array can hav negative numbers also..

Answer Posted / sathish

Just count the number of -ve symbols in the array before sorting.

CODE:
void main()
{
clrscr();
int i,j,count=0,a[5]={10,2,-7,-5,3};
for(i=0;i<5;i++)
if(a[i]<0)
count=count+1;
if((count%2)==0)
{
for(i=0;i<5;i++)
{

if(a[i]<0)
a[i]=-a[i];
}
}
for(i=0;i<5;i++)
{
for(j=i;j<5;j++)
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
int mul=1;
for(i=0;i<3;i++)
{
mul=mul*a[i];
}
cout<<mul;
getch();
}

Is This Answer Correct ?    9 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write a program that can LOCATE and INSERT elements in array using c++ programming languages.

3440


create a stucture student containing field for roll no,class,year and marks.create 10 student annd store them in a file

2220


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

2066


write a program to convert temperature from fa height into celcius and vise versa,use modular programming

2441


write a function that allocates memory for a single data type passed as a parameter.the function uses the new operator and return a pointer to the allocated memory.the function must catch and handle any exception during allocation

2407






write a program that reads a series of strings and prints only those strings begging with letter "b"

2674


U hv to enter a range from a and b and search hw many no. of times a pattern n. occurs between the range a and b. Eg :i/p:enter range :0 100 Enter pattern: 13 o/p: the no. times 13 occurred betwwn 0 to 100:1 Eg :i/p:enter range :100 1000 Enter pattern: 13 o/p: the no. times 13 occurred betwwn 100 to 1000: (in this 13,113,131,132,133…139,213,313,…913 all these will be counted)

2125


find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L

2010


write a program to perform generic sort in arrays?

2628


Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

4579


develop a program to calculate and print body mass index for 200 employees

2216


how to write a program that opens a file and display in reverse order?

2567


What output does the following code generate? Why? What output does it generate if you make A::Foo() a pure virtual function? class A { A() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; class B : public A { B() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; int main(int, char**) { A objectA; B objectB; return 0; }

644


Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

2198


write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.

3958