5
22/10/2024 4:46 pm
Topic starter
Write a program, which prints all unique pairs in an array of integers whose sum is equal to a given number.
Examples:
1 Answer
4
22/10/2024 4:47 pm
My solution:
<?php $array = array_map('intval', explode(' ', readline())); $number = intval(readline()); $count = count($array); for ($i = 0; $i < $count; $i++) { for ($j = $i + 1; $j < $count; $j++) { if ($array[$i] + $array[$j] == $number) { echo $array[$i] . ' ' . $array[$j] . PHP_EOL; } } }