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

1)Sort the array in descending order.
2)Multiply for required number of indices.

CODE:

int mul=1;
for(i=0;i<3;i++)
{
mul=mul*a[i];
}
cout<<mul;

Is This Answer Correct ?    11 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?

2658


i don't know about working of nested for loop can any one help me

1894


Write a simple encryption program using string function which apply the substitution method.

5627


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

2167


write a program using virtual function to find the transposing of a square matrix?

2964






i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.

2095


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; }

734


write a program to perform generic sort in arrays?

2716


write a program that prompt the user to enter his height and weight,then calculate the body mass index and show the algorithm used

4440


How can I Draw an ellipse in 3d space and color it by using graph3d?

2230


A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect

2520


3. Program to find the Sum of give series. a. (1)+(1+2)+(1+2+3)+(1+2+3+4)+……………………………….. b. 1/1+1/9+1/25+1/49+……………...

4456


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

2328


How to Split Strings with Regex in Managed C++ Applications?

3206


Question 1: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date. *This Should Be Done IN C++

663