CJCoding With Joseph
15free / daySign inCreate account

Count Pairs Summing to a Target

The array {1, 5, 7, -1, 5} is given. Read a target integer from standard input, then count how many index pairs (i, j) with i < j satisfy arr[i] + arr[j] == target, and print that count.

For example, if the input is 6, print the output shown in Expected Output.

The pairs summing to 6 are (1,5), (1,5), and (7,-1). Each unordered pair of positions is counted once.

Expected Output:

3

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Arrays
📥 Auto-Input:
6\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.