Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions 2-variables/quadratic-formula/Quadratic.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
// Quadratic Formula 📈
// Sonny Li
// Patrick Jakobsen

var a: Double = 6
var b: Double = -7
var c: Double = -3
let a = 6.0
let b = -7.0
let c = -3.0

var root1: Double
var root2: Double
let discriminant = (b * b - 4 * a * c).squareRoot()

// The positive root
root1 = (-b + (b*b - 4*a*c).squareRoot()) / (2*a)
let root1 = (-b + discriminant) / (2 * a)
let root2 = (-b - discriminant) / (2 * a)

// The negative root
root2 = (-b - (b*b - 4*a*c).squareRoot()) / (2*a)

// Outputting the roots
print("Root 1 is \(root1)")
print("Root 2 is \(root2)")
print("Root 1:", root1)
print("Root 2:", root2)