Starting Files
The Problem
/// Challenge: Use the quadratic formula x = (b ± √(b^2  4ac))/(2a) to calculate the two roots of a quadratic polynomial and store it into the array named "roots"
/**
Return an array that consists of the roots of a quadratic polynomial ax^2 + bx + c.
 Parameter coefficients: An array with the coefficients of the terms of a quadratic polynomial.
 Returns: an array of the quadratic polynomial's roots.
*/
func quadraticFormula(coefficients: [Double]) > [Double]{
var roots = [Double]()
// Calculate the roots and append them into the roots array!
// YOUR CODE HERE
return roots
}
You are given an array with the coefficients of the terms of a quadratic polynomial named “coefficients”.
In a quadratic polynomial ax^2 + bx + c, the first element of the array would represent a, the second element represents b and the last element represents c.
Use the quadratic formula x = (b ± √(b^2 – 4ac))/(2a) to calculate the two roots of a quadratic polynomial and store it into the array named “roots”
Hint: Use Google to figure out how to square root something in Swift.
Googling is an essential skill for programmers!
Upload your screenshot here!
Upload files





