Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 / jack

#include"stdafx.h"
#include<iostream>


using namespace std;
void sort(int[],int );
int maxproduct(int ar[],int n);
int main()
{
int arr[]={2,7,9,5,3,6,-12};

cout<<maxproduct(arr,7);
system("calc");


system("pause");
return 0;
}
void sort(int array1[],int n)
{
for(int i=1;i<n;i++)
for(int r=0;r<n-1;r++)

if(array1[r]>array1[r+1])
{
int temp=array1[r];
array1[r]=array1[r+1];
array1[r+1]=temp;
}

}
int maxproduct(int ar[],int n)
{
sort(ar,n);
int max=1;
for(int i=n-1;i>=n-3;i--)
max*=ar[i];
return max;
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Code for Method of Handling Factorials of Any Size?

2491


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

3470


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

3386


1+1/2!+1/3!+...+1/n!

2421


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

3075


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

3246


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

3686


output for printf("printf");

2553


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?

7843


How to swap two ASCII numbers?

3054


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?

3372


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

2690


how to take time as input in the format (12:02:13) from user so that controls remains between these columns?

2280


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

6136


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

5124