Q:

Write a PHP program which solve the equation:

0

Write a PHP program which solve the equation:
ax+by=c
dx+ey=f
Print the values of x, y where a, b, c, d, e and f are given.

Input:
a,b,c,d,e,f separated by a single space.
(-1,000 ≤ a,b,c,d,e,f ≤ 1,000)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
  function to_f($e) {
    return (float)$e;
  } 
  while($line = fgets(STDIN)) {
    $a = explode(" ", $line);
    $a = array_map("to_f", $a);
    $x = ($a[2]*$a[4]-$a[1]*$a[5])/($a[0]*$a[4]-$a[3]*$a[1]);
    $y = ($a[2]*$a[3]-$a[0]*$a[5])/($a[1]*$a[3]-$a[0]*$a[4]);
    print("Values of x and y:\n");
    printf("%.3f %.3f\n", $x, $y);
  }
?>

Sample Output:

Values of x and y:
-1.684 2.737

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now