Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by Alex Malyi.
- * User: https://vk.com/m1step
- * Git: https://github.com/m1step
- * Date: 20.10.2017
- */
- /**
- * @param $first
- * @param $second
- * @param $third
- *
- * Поиск решения через дискриминант
- *
- * @return array|float|int|string
- */
- function discriminant($first, $second, $third)
- {
- $discriminant = pow($second, 2) - 4 * $first * $third;
- switch ($discriminant) {
- case $discriminant < 0;
- return 'Решений нет';
- case $discriminant == 0:
- return $second * (-1) / 2 * $first;
- default:
- $x1 = ($second * (-1) - sqrt($discriminant)) / 2 * $first;
- $x2 = ($second * (-1) + sqrt($discriminant)) / 2 * $first;
- return [
- 'first_issue' => $x1,
- 'second_issue' => $x2
- ];
- }
- }
- /**
- * @param $first
- * @param $second
- * @param $third
- *
- *
- * @return array|float|int|string
- */
- /*function vietta($first, $second, $third)
- {
- $first_issue = false;
- $second_issue = false;
- $first_issue + $second_issue = $second / $first * (-1);
- $first_issue * $second_issue = $third / $first;
- return true;
- }*/
- /**
- * @param $arr string|integer|array
- */
- function debug($arr)
- {
- echo '<pre>' . print_r($arr, true) . '</pre>';
- }
- ?>
- <!DOCTYPE html><html lang="ru">
- <head>
- <meta charset="UTF-8">
- <title>Count</title>
- </head>
- <body>
- <form action="" method="POST">
- <label for="first_var">Первая переменная</label>
- <input type="number" name="first_var" id="first_var">
- <label for="second_var">Вторая переменная</label>
- <input type="number" name="second_var" id="second_var">
- <label for="third_var">Третяя переменная</label>
- <input type="number" name="third_var" id="third_var">
- <label for="checkbox">Посчитать виетта</label>
- <input type="checkbox" value="1" id="checkbox" name="boolean">
- <input type="submit" value="Посчитать">
- </form>
- </body>
- </html>
- <?php
- if($_POST) {
- if (!isset($_POST['boolean'])) {
- debug(discriminant($_POST['first_var'], $_POST['second_var'], $_POST['third_var']));
- } else {
- debug('Здесь мы должны написать теорему Виета');
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement