Created
April 3, 2020 22:26
-
-
Save asa55/f1b3fc0855c2109cf8d1cb69b0a42752 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How do you find all pairs of an integer array whose sum is equal to a given number? | |
#include <iostream> | |
#include <array> | |
int desired_sum = 10; | |
std::array<int, 10> arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | |
int main () | |
{ | |
int i, j; | |
for ( i = 0; i < arr.size(); ++i) | |
for ( j = i; j < arr.size(); ++j ) | |
if ( arr[i] + arr[j] == desired_sum ) | |
std::cout << i << " " << j << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment