Skip to content

Instantly share code, notes, and snippets.

@Headmast
Last active October 3, 2020 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Headmast/3949a1dff165c9dad2243b636fba0957 to your computer and use it in GitHub Desktop.
Save Headmast/3949a1dff165c9dad2243b636fba0957 to your computer and use it in GitHub Desktop.
import 'dart:math';
String solve({double ax, double bx, double cx}) {
double discriminant({double a, double b, double c}) {
return (b*b - 4*a*c);
}
double calculateX({double a, double b, double c, int xType = 1}) {
double singDiscr;
final sqrtD = sqrt(discriminant(a: a, b:b, c:c));
if (xType == 1) {
singDiscr = -sqrtD;
} else {
singDiscr = sqrtD;
}
return (-b + singDiscr)/(2*a);
}
final d = discriminant(a: ax, b:bx, c:cx);
if (d < 0) {
return 'No answer';
} else if (d == 0) {
return 'One answer ${-bx/(2*ax)}';
} else {
return 'Two answer ${calculateX(a: ax, b:bx, c:cx, xType: 1)} and ${calculateX(a: ax, b:bx, c:cx, xType:2)}';
}
return '';
}
void main() {
double ax = 3;
double bx = 1;
double cx = -1;
print(solve(ax: ax, bx: bx, cx:cx));
}
@artem-zaitsev
Copy link

Доп. задание:

  • сделайте так, чтобы коэффициенты передавались в функцию через именованные параметры

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment