forked from root/public
Compare commits
6 Commits
master
...
1127-print
Author | SHA1 | Date |
---|---|---|
Hamza elkhatri | d2e6f88b2d | 2 years ago |
Hamza elkhatri | a228306fbb | 2 years ago |
Hamza elkhatri | 4bdd0f194f | 2 years ago |
Hamza elkhatri | 95858f3b00 | 2 years ago |
Hamza elkhatri | bf6ba5c725 | 2 years ago |
hamza | 766ecd5b8d | 2 years ago |
1 changed files with 50 additions and 0 deletions
@ -0,0 +1,50 @@ |
|||||||
|
## print-range |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function called `PrintRange` that given a range between two numbers, prints all numbers in that range. |
||||||
|
|
||||||
|
- If the starting number is greater than the ending number, print the numbers in descending order, otherwise in ascending order. |
||||||
|
- If the number is greater than `9` print only up to `9` |
||||||
|
- If the number is less than '0' print only up to '0' |
||||||
|
- If both numbers are less than `0` print (`'\n'`), the same applies when both numbers are greater than 9. |
||||||
|
- The output must be separated by spaces and (`'\n'`) at the end. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func PrintRange(start, end int) { |
||||||
|
// Your code here |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible program to test your function: |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import "fmt" |
||||||
|
|
||||||
|
func main() { |
||||||
|
PrintRange(1, 10) |
||||||
|
PrintRange(10, 1) |
||||||
|
PrintRange(1, 1) |
||||||
|
PrintRange(10, 10) |
||||||
|
PrintRange(0, 9) |
||||||
|
PrintRange(-1, -10) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
and the output should be: |
||||||
|
|
||||||
|
```console |
||||||
|
$ go run . | cat -e |
||||||
|
1 2 3 4 5 6 7 8 9$ |
||||||
|
9 8 7 6 5 4 3 2 1$ |
||||||
|
1$ |
||||||
|
$ |
||||||
|
0 1 2 3 4 5 6 7 8 9$ |
||||||
|
$ |
||||||
|
``` |
Loading…
Reference in new issue