public/subjects/squareroot/README.md

50 lines
775 B
Markdown
Raw Permalink Normal View History

2022-06-17 21:30:19 +00:00
## Square-root
### Instructions
Write a function that takes a number and returns the square root of that number.
- The square root of a number is the number divided by two until the number is less than or equal to one.
2022-06-20 15:29:21 +00:00
- If the number is less than zero return `-1`.
2022-06-17 21:30:19 +00:00
### Expected function
2022-07-07 21:51:25 +00:00
2022-06-17 21:30:19 +00:00
```go
func SquareRoot(number int) int {
// Your code here
}
```
### Usage
2022-06-20 15:29:21 +00:00
Here is a possible program to test your function:
2022-06-17 21:30:19 +00:00
```go
package main
2022-06-20 15:36:56 +00:00
import (
"fmt"
2022-07-07 21:51:25 +00:00
)
2022-06-17 21:30:19 +00:00
func main() {
2022-07-07 21:51:25 +00:00
fmt.Println(SquareRoot(9))
fmt.Println(SquareRoot(16))
fmt.Println(SquareRoot(25))
fmt.Println(SquareRoot(26))
fmt.Println(SquareRoot(0))
fmt.Println(SquareRoot(-1))
fmt.Println(SquareRoot(1))
2022-06-17 21:30:19 +00:00
}
```
and the output should be:
```console
$ go run .
3
4
5
2022-06-20 15:29:21 +00:00
5
0
2022-06-17 21:30:19 +00:00
-1
2022-06-20 15:29:21 +00:00
1
2022-07-07 21:51:25 +00:00
```