Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- long double hasElement(int array[], int size)
- {
- int l = 0;
- int r = size - 1;
- sort(array, array + size);
- while (l < r)
- {
- if (array[l] + array[r] == 2020)
- {
- return array[l] * array[r];
- }
- else if (array[l] + array[r] < 2020)
- {
- l++;
- }
- else if (array[l] + array[r] > 2020)
- {
- r--;
- }
- }
- return 0;
- }
- int main()
- {
- int A[] = {1721,
- 979,
- 366,
- 299,
- 675,
- 1456};
- int arr_size = sizeof(A) / sizeof(A[0]);
- // Function calling
- cout << hasElement(A, arr_size) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement