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

can you please write a program for deadlock that can detect deadlock and to prevent deadlock.

2931


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

3505


Performance Algorithm A performs 10n2 basic operations and algorithm B performs 300 lg n basic operations. For what value of n does algorithm B start to show its better performance?

7604


Write a (n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)

4705


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.

2272


Definition of priority queue was given. We have to implement the priority queue using array of pointers with the priorities given in the range 1..n. The array could be accessed using the variable top. The list corresponding to the array elements contains the items having the priority as the array index. Adding an item would require changing the value of top if it has higher priority than top. Extracting an item would require deleting the first element from the corresponding queue. The following class was given: class PriorityQueue { int *Data[100]; int top; public: void put(int item, int priority); // inserts the item with the given priority. int get(int priority); // extract the element with the given priority. int count(); // returns the total elements in the priority queue. int isEmpty(); // check whether the priority queue is empty or not. }; We had to implement all these class functions.

4641


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

3091


how to diplay a external image of output on winxp by using c & c++,

3163


What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }

789


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

4593


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

3379


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

2680


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

4584


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

2776


Code for Easily Using Hash Table?

2636