Last active
September 14, 2017 04:39
-
-
Save ItsMurumba/27c9430c48545adebc5a17f4c07668ab to your computer and use it in GitHub Desktop.
max_pair
This file contains hidden or 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
| <?php | |
| function max_pair($A){ | |
| $n=sizeof($A); | |
| //Initialize the max sum | |
| $a=$A[0]; | |
| $b=$A[1]; | |
| for($i=0;$i<$n;$i++){ | |
| for($j=$i+1;$j<$n;$j++){ | |
| if($A[$i]+$A[$j]>$a+$b){ | |
| $a=$A[$i]; | |
| $b=$A[$j]; | |
| } | |
| } | |
| } | |
| print "The pair that gives a max comnibation is:" . $a .",".$b; | |
| } | |
| max_pair([10, 5, 6, 3, 9]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment