SolveSquareEquation. PHP Tutorials. Simple Input/Output. Algorithms. Console Application. A console application in the PHP programming language. The program does the following:
- Asks you to enter the coefficients of a quadratic equation that needs to be solved.
- Displays the equation being solved in linear form on the screen.
- Checks if the entered coefficients are equal to 0.
- The following cases are possible:
- All coefficients are equal to zero. The phrase "Solution - any number" will be displayed on the screen.
- The coefficients "a" and "b" are equal to zero, but "c" is not. In this case, the message "The equation has no solutions" will be displayed.
- The coefficient "a" is zero, but "b" and "c" are not. In this case, the solution calculated using the formula "x=-c/b" will be displayed on the screen.
- All coefficients are non-zero. Then the quadratic equation is solved:
- The discriminant is found using the formula "d=bb-4a*c".
- The sign of the previously obtained expression is calculated (can be: -1, 0, 1). 1 is added to the value.
- This is the number of roots of the quadratic equation.
- If the number of roots of a quadratic equation is greater than zero (can be 0, 1 or 2), then the program displays solutions to formulas "x1=-b-sqrt(d)/(2a)" and "x2=-b+sqrt(d)/(2a)". Otherwise, the phrase "the equation has no roots" is displayed. Developed in the Apache NetBeans integrated environment (in the Microsoft Visual Studio Code editor).
SolveSquareEquation. Занятия по PHP. Простой Ввод/вывод. Алгоритмы. Консольное приложение. Консольное приложение написанное на языке программирования PHP. Программа делает следующее:
- Просит ввести коэффицееты квадратного уравнения, которое нужно решить.
- Выводит на экран запись решаемое уравнение в линейной форме.
- Проверяет введённые коэффициенты на равенство 0.
- Далее возможны следующие случаи:
- Все коэффициенты равны нулю. На экран будет выведена фраза на английском языке "Решение - любое число".
- Коэффициенты "a" и "b" равны нулю, а "с" нет. В данном случае будет выдано сообщение "Уравнение не имеет решений".
- Коэффициент "a" равен нулю, а "b" и "с" нет. В этом случае на экран будет выведено решение, вычисляемое по формуле "x=-с/b".
- Все коэффицинеты не равны нулю. Тогда решается квадратное уравнение:
- Находится дискриминант по формуле "d=bb-4a*c".
- Вычисляется знак выражения, полученного ранее. (можент быть: -1, 0, 1). К значению прибавляется 1.
- Это и есть число корней квадратного уравнения.
- Если число корней квадратного уравнения больше нуля (может быть 0, 1 или 2), то на экран выводятся решения по фомулам "x1=-b-sqrt(d)/(2a)" и "x2=-b+sqrt(d)/(2a)". В противном случае выводится фраза "уравнение не имеет корней". Разработано в интегрированной среде Apache NetBeans (в редакторе Microsoft Visual Studio Code).