Last active
October 3, 2020 13:30
-
-
Save Headmast/3949a1dff165c9dad2243b636fba0957 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
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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Доп. задание: