forked from rathoresrikant/HacktoberFestContribute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewfile.cpp
37 lines (31 loc) · 756 Bytes
/
newfile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// A simple C++ program to find max product pair in
// an array of integers
#include<bits/stdc++.h>
using namespace std;
// Function to find maximum product pair in arr[0..n-1]
void maxProduct(int arr[], int n)
{
if (n < 2)
{
cout << "No pairs exists\n";
return;
}
// Initialize max product pair
int a = arr[0], b = arr[1];
// Traverse through every possible pair
// and keep track of max product
for (int i=0; i<n; i++)
for (int j=i+1; j<n; j++)
if (arr[i]*arr[j] > a*b)
a = arr[i], b = arr[j];
cout << "Max product pair is {" << a << ", "
<< b << "}";
}
// Driver program to test
int main()
{
int arr[] = {1, 4, 3, 6, 7, 0};
int n = sizeof(arr)/sizeof(arr[0]);
maxProduct(arr, n);
return 0;
}