CJCoding With Joseph
15per day

Print Pairs that Sum to Target

An array called nums has already been created for you with the values {10, 20, 30, 40, 50}. A variable called target has been set to 60.

Your task is to find and print all pairs of elements that add up to the target value.

To check all possible pairs, you need two nested loops. The outer loop picks the first element (index i), and the inner loop picks the second element (index j, where j > i). This ensures you don't repeat pairs or pair an element with itself.

For each pair that sums to 60, print it in this format:
10 + 50 = 60

Expected output:
10 + 50 = 60
20 + 40 = 60

Expected Output:

10 + 50 = 60
20 + 40 = 60
Topics:
Arrays
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.