/
pmv014
/
seminar1
Обзор
Документация
Войти
/
pmv014
/
seminar1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task3
33 строки
881 B
pmv014
update task3
02 окт 2025, 17:27
02 окт 2025, 17:27
9dfec71
Код
Авторство
О чём код?
import Foundation enum Solution { case noSolution case oneRoot(Double) case twoRoots(x1: Double, x2: Double) } func solveQuadratic(a: Double, b: Double, c: Double) -> Solution { let discriminant = b * b - 4 * a * c if discriminant < 0 { return .noSolution } else if discriminant == 0 { let root = -b / (2 * a) return .oneRoot(root) } else { let x1 = (-b + sqrt(discriminant)) / (2 * a) let x2 = (-b - sqrt(discriminant)) / (2 * a) return .twoRoots(x1: x1, x2: x2) } } func printSolution(_ solution: Solution) { switch solution { case .noSolution: print("Решений нет") case .oneRoot(let x): print("Один корень: \(x)") case .twoRoots(let x1, let x2): print("Два корня: \(x1) и \(x2)") } }