fork download
  1. package main
  2. import (
  3. "fmt"
  4. "math"
  5. )
  6. func solve(a, b, c float64) {
  7. d := b*b - 4*a*c
  8. if d < 0 {
  9. fmt.Println("No real roots")
  10. } else {
  11. r1 := (-b + math.Sqrt(d)) / (2 * a)
  12. r2 := (-b - math.Sqrt(d)) / (2 * a)
  13. fmt.Println("Roots:", r1, r2)
  14. }
  15. }
  16. func main() {
  17. solve(1, -3, 2)
  18. }
  19.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Roots: 2 1