Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by Alex Malyi.
  4. * User: https://vk.com/m1step
  5. * Git: https://github.com/m1step
  6. * Date: 20.10.2017
  7. */
  8.  
  9.  
  10. /**
  11. * @param $first
  12. * @param $second
  13. * @param $third
  14. *
  15. * Поиск решения через дискриминант
  16. *
  17. * @return array|float|int|string
  18. */
  19. function discriminant($first, $second, $third)
  20. {
  21. $discriminant = pow($second, 2) - 4 * $first * $third;
  22. switch ($discriminant) {
  23. case $discriminant < 0;
  24. return 'Решений нет';
  25. case $discriminant == 0:
  26. return $second * (-1) / 2 * $first;
  27. default:
  28. $x1 = ($second * (-1) - sqrt($discriminant)) / 2 * $first;
  29. $x2 = ($second * (-1) + sqrt($discriminant)) / 2 * $first;
  30. return [
  31. 'first_issue' => $x1,
  32. 'second_issue' => $x2
  33. ];
  34. }
  35. }
  36.  
  37. /**
  38. * @param $first
  39. * @param $second
  40. * @param $third
  41. *
  42. *
  43. * @return array|float|int|string
  44. */
  45. /*function vietta($first, $second, $third)
  46. {
  47. $first_issue = false;
  48. $second_issue = false;
  49.  
  50. $first_issue + $second_issue = $second / $first * (-1);
  51. $first_issue * $second_issue = $third / $first;
  52.  
  53. return true;
  54. }*/
  55.  
  56. /**
  57. * @param $arr string|integer|array
  58. */
  59. function debug($arr)
  60. {
  61. echo '<pre>' . print_r($arr, true) . '</pre>';
  62. }
  63.  
  64. ?>
  65. <!DOCTYPE html><html lang="ru">
  66. <head>
  67. <meta charset="UTF-8">
  68. <title>Count</title>
  69. </head>
  70. <body>
  71. <form action="" method="POST">
  72. <label for="first_var">Первая переменная</label>
  73. <input type="number" name="first_var" id="first_var">
  74. <label for="second_var">Вторая переменная</label>
  75. <input type="number" name="second_var" id="second_var">
  76. <label for="third_var">Третяя переменная</label>
  77. <input type="number" name="third_var" id="third_var">
  78. <label for="checkbox">Посчитать виетта</label>
  79. <input type="checkbox" value="1" id="checkbox" name="boolean">
  80. <input type="submit" value="Посчитать">
  81. </form>
  82. </body>
  83. </html>
  84.  
  85. <?php
  86. if($_POST) {
  87. if (!isset($_POST['boolean'])) {
  88. debug(discriminant($_POST['first_var'], $_POST['second_var'], $_POST['third_var']));
  89. } else {
  90. debug('Здесь мы должны написать теорему Виета');
  91. }
  92. }
  93.  
  94.  
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement