2022-06-14 14:08:10 +00:00
|
|
|
## CountStars
|
|
|
|
|
|
|
|
### Instructions
|
2022-07-14 15:39:04 +00:00
|
|
|
|
|
|
|
Write a function called `CountStars` that counts the stars up to a number given as an argument.
|
|
|
|
|
2022-06-30 17:38:29 +00:00
|
|
|
- If the number is negative or equal to 0, return "`No stars`"
|
2022-06-14 14:08:10 +00:00
|
|
|
- No need to manage overflow.
|
|
|
|
|
2022-06-30 17:38:29 +00:00
|
|
|
### Expected Function
|
|
|
|
|
2022-06-14 14:08:10 +00:00
|
|
|
```go
|
2022-06-14 14:16:00 +00:00
|
|
|
func CountStars(num int) string {
|
2022-06-14 14:08:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
```
|
2022-07-14 15:39:04 +00:00
|
|
|
|
2022-06-30 17:38:29 +00:00
|
|
|
### Usage
|
|
|
|
|
|
|
|
Here is a possible program to test your function :
|
|
|
|
|
2022-06-14 14:08:10 +00:00
|
|
|
```go
|
2022-07-14 15:39:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
2022-06-14 14:08:10 +00:00
|
|
|
|
|
|
|
func main() {
|
2022-06-14 14:16:00 +00:00
|
|
|
fmt.Println(CountStars(5))
|
|
|
|
fmt.Println(CountStars(4))
|
|
|
|
fmt.Println(CountStars(-1))
|
2022-06-15 11:41:01 +00:00
|
|
|
fmt.Println(CountStars(1))
|
2022-06-14 14:08:10 +00:00
|
|
|
}
|
|
|
|
```
|
2022-07-03 10:17:12 +00:00
|
|
|
And its output :
|
|
|
|
|
2022-06-14 14:08:10 +00:00
|
|
|
```console
|
2022-06-15 11:27:28 +00:00
|
|
|
$ go run .
|
2022-06-15 11:41:01 +00:00
|
|
|
1 star...2 stars...3 stars...4 stars...5 stars
|
|
|
|
1 star...2 stars...3 stars...4 stars
|
2022-06-30 17:38:29 +00:00
|
|
|
No stars
|
2022-06-15 11:41:01 +00:00
|
|
|
1 star
|
2022-06-14 14:08:10 +00:00
|
|
|
```
|