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
how to write a program that opens a file and display in reverse order?
Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?
Create a program to read two random data set in two files named data1.txt and data2.txt manifold contains integer numbers, whereas data2.txt file contains the float type numbers. Simpanlahmasing each into 2 pieces of data that is an array of type integer array and an array of type float, then calculate the average numbers in the second array.
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!!!)
how to diplay a external image of output on winxp by using c & c++,
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+……………...
How to swap two ASCII numbers?
how to take time as input in the format (12:02:13) from user so that controls remains between these columns?
Code for Easily Using Hash Table?
i don't know about working of nested for loop can any one help me
Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).
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.
Write a simple encryption program using string function which apply the substitution method.
Implement a command console for changing settings on a particular object. The command console should allow you to enter a string and will return the response (very similar to a terminal session). The commands are as follows: SET propertyname=newvalue will change the target object’s member named “propertyname” to have a value equal to “newvalue”. If the input value is incompatible (i.e. an int being set to a string), print out an appropriate error message. GET propertyname will print out the current value of the target object’s member named “propertyname”. GET * will print out a list of all target object members and their current values. The system should be extensible for future commands and should accept an arbitrary object, such that another developer could insert another object into the system and rely on the command console to get and set the properties correctly.
write a program using virtual function to find the transposing of a square matrix?