Skip to content

Commit

Permalink
Maximum Product
Browse files Browse the repository at this point in the history
This is the code in C++ to return the numbers in the Array having the Maximum Product
  • Loading branch information
ankurgupta255 committed Oct 28, 2018
1 parent bed7db9 commit 1fbf4d0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Algorithms/MaxPro.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<iostream>
using namespace std;
int main()
{
int n;
int a[100];
int i=0;
int j=0;
int cnt=0;
int n1=0;
int n2=0;
cout<<"Enter the size of the array: ";
cin>>n;
cout<<"Enter the array Elements: ";
for(i=0;i<n;i++){
cin>>a[i];
}
int pro=a[0]*a[1];
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if((a[i]*a[j])>pro){
n1=a[i];
n2=a[j];
pro=a[i]*a[j];
}
}
}
cout<<"The 1st number is "<<n1<<endl;
cout<<"The 2nd number is "<<n2<<endl;
cout<<"The maximum product is "<<pro;
return 0;
system("PAUSE");
}

0 comments on commit 1fbf4d0

Please sign in to comment.