Browse Source

squareroot

DEV-3241-DEV-3242-corewar
zainabdnaya 2 years ago committed by Dav Hojt
parent
commit
f3a1b74bd9
  1. 10
      subjects/squareroot/README.md

10
subjects/squareroot/README.md

@ -2,8 +2,8 @@
### Instructions ### Instructions
Write a function that takes a number and returns the square root of that number. Write a function that takes a number and returns the square root of that number.
- If the number is less than one or the number does not have an integer square root, return `-1`.
- The square root of a number is the number divided by two until the number is less than or equal to one. - The square root of a number is the number divided by two until the number is less than or equal to one.
- If the number is less than zero return `-1`.
### Expected function ### Expected function
```go ```go
@ -14,6 +14,8 @@ func SquareRoot(number int) int {
### Usage ### Usage
Here is a possible program to test your function:
```go ```go
package main package main
@ -25,6 +27,8 @@ func main() {
fmt.Println(SquareRoot(25)) fmt.Println(SquareRoot(25))
fmt.Println(SquareRoot(26)) fmt.Println(SquareRoot(26))
fmt.Println(SquareRoot(0)) fmt.Println(SquareRoot(0))
fmt.Println(SquareRoot(-1))
fmt.Println(SquareRoot(1))
} }
``` ```
@ -35,6 +39,8 @@ $ go run .
3 3
4 4
5 5
5
0
-1 -1
-1 1
``` ```
Loading…
Cancel
Save