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
write a program using 2 D that searches a number and display the number of items 12 inputs values input 15,20, 13, 30, 38, 40,16, 18, 20 ,18 ,20 enter no. to search : 20
We need to write the function to check the password entered is correct or not based on the following conditions.. a) It must have atleast one lower case character and one digit. b)It must not have any Upper case characters and any special characters c) length should be b/w 5-12. d) It should not have any same immediate patterns like abcanan1 : not acceptable coz of an an pattern abc11se: not acceptable, coz of pattern 11 123sd123 : acceptable, as not immediate pattern adfasdsdf : not acceptable, as no digits Aasdfasd12: not acceptable, as have uppercase character
create a stucture student containing field for roll no,class,year and marks.create 10 student annd store them in a file
Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?
1+1/2!+1/3!+...+1/n!
output for printf("printf");
write a program that reverses the input number of n.Formulate an equation to come up with the answer.
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?
how to take time as input in the format (12:02:13) from user so that controls remains between these columns?
write a program using virtual function to find the transposing of a square matrix?
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
i don't know about working of nested for loop can any one help me
Code for Method of Handling Factorials of Any Size?
write a program to perform generic sort in arrays?
How to swap two ASCII numbers?