[ create a new paste ] login | about

Link: http://codepad.org/LSgMM57G    [ raw code | output | fork ]

PHP, pasted on Mar 7:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

    $sum = 5;
    $product = 6;

    $found = FALSE;
    for ($a = 1; $a < $sum; $a++) {
      $b = $sum - $a;
      if ($a * $b == $product) {
        $found = TRUE;
        break;
      }
    }

    if ($found) {
      echo "The answer is a = $a, b = $b.";
    } else {
      echo "There is no answer where a and b are both integers.";
    }


Output:
1
The answer is a = 2, b = 3.


Create a new paste based on this one


Comments: