Last active
March 16, 2021 09:58
-
-
Save ibrohimkhan/10a3db957ad49a2c6a3ce14583fd6e4b 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'; | |
| void main() { | |
| task1(); | |
| print(task2(numbers: [1, 2, 3, 4])); | |
| print(task4()); | |
| } | |
| void task1([String a = 'hello world']) => print(a.split(' ').reversed.join(' ')); | |
| double task2({List<num> numbers = const [1, 2, 3, 4, 5, 15]}) { | |
| var sum = numbers.reduce((value, element) => value + element); | |
| return sum / numbers.length; | |
| } | |
| String task4({num a = 1, num b = -8, num c = 7}) { | |
| // helper inner functions | |
| num findDiscriminant(num a, num b, num c) => b * b - 4 * a * c; | |
| num findX(num a, num b) => -b / (2 * a); | |
| num findX1(num a, num b, num d) => (-b + sqrt(d)) / (2 * a); | |
| num findX2(num a, num b, num d) => (-b - sqrt(d)) / (2 * a); | |
| // calculations | |
| var d = findDiscriminant(a, b, c); | |
| if (d > 0) { | |
| var x1 = findX1(a, b, d); | |
| var x2 = findX2(a, b, d); | |
| return 'Корни уравнения: x1 = $x1 и x2 = $x2'; | |
| } else if (d == 0) { | |
| var x = findX(a, b); | |
| return 'Уравнение имеет единственный корень: x = $x'; | |
| } else { | |
| return 'Уравнение не имеет действительных корней!'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment