Skip to content

Commit

Permalink
Create exercise-loops-and-functions.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mitDarkMomo authored May 28, 2018
1 parent ff30a1a commit e22c66a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions exercise-loops-and-functions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"fmt"
"math"
)

func Sqrt(x float64) float64 {
t,z := 0.0, 1.0
for {
z, t = z - (z*z - x)/(2*z), z
// fmt.Printf("z is %v & t is %v. \n", z, t)
if math.Abs(z - t) < 1e-8 {
break
}
}
return z
}

func main() {
i := 2.
fmt.Println(Sqrt(i))
fmt.Println(Sqrt(i) == math.Sqrt(i))
}

0 comments on commit e22c66a

Please sign in to comment.