Last active
March 16, 2021 17:23
-
-
Save internetova/6f93b5d0744e199b4f5a8230a32cb45a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Задание 4 | |
// Напишите функцию решения квадратного уравнения, используя вложенные функции. | |
// Вычисление дискриминанта, нахождение x1 и x2 выполните во вложенных функциях. | |
// Главная функция должна возвращать готовый результат. Функция возвращает ответ в строке (String). | |
import 'dart:math'; | |
void main() { | |
final result = solveQuadraticEquation(1, -2, -3); | |
print(result); | |
} | |
String solveQuadraticEquation(int a, int b, int c) { | |
if (a == 0) { | |
return 'а не может быть 0!'; | |
} | |
int findDiscriminant() => b * b - 4 * a * c; | |
final D = findDiscriminant(); | |
num findX1() => (-b + sqrt(D)) / 2 * a; | |
num findX2() => (-b - sqrt(D)) / 2 * a; | |
if (D < 0) { | |
return 'корней нет'; | |
} else if (D == 0) { | |
return 'есть один корень: ${findX1()}'; | |
} else { | |
return 'корней будет два: x1 = ${findX1()}, x2 = ${findX2()}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment