mirror of https://github.com/01-edu/public.git
docs(gcd): update subject to require a function instead of a program
- add main.go to test the function in exam mode
This commit is contained in:
parent
d07d9d681c
commit
529e5c8fdb
|
@ -2,26 +2,46 @@
|
||||||
|
|
||||||
### Instructions
|
### Instructions
|
||||||
|
|
||||||
Write a program that takes two `string` representing two strictly positive integers that fit in an `int`.
|
Write a function that takes two `uint` representing two strictly positive integers and returns their greatest common divisor.
|
||||||
|
If any of the input numbers is 0, the function should return 0.
|
||||||
|
|
||||||
The program displays their greatest common divisor followed by a newline (`'\n'`).
|
> [In mathematics, the greatest common divisor (GCD) of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers.](https://en.wikipedia.org/wiki/Greatest_common_divisor)
|
||||||
|
|
||||||
If the number of arguments is different from 2, the program displays nothing.
|
### Expected function
|
||||||
|
|
||||||
All arguments tested will be positive `int` values.
|
```go
|
||||||
|
func Gcd(a, b uint) uint {
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
|
Here is a possible program to test your function:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"piscine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(piscine.Gcd(42, 10))
|
||||||
|
fmt.Println(piscine.Gcd(42, 12))
|
||||||
|
fmt.Println(piscine.Gcd(14, 77))
|
||||||
|
fmt.Println(piscine.Gcd(17, 3))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
And its output :
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ go run . 42 10 | cat -e
|
|
||||||
2$
|
|
||||||
$ go run . 42 12
|
|
||||||
6
|
|
||||||
$ go run . 14 77
|
|
||||||
7
|
|
||||||
$ go run . 17 3
|
|
||||||
1
|
|
||||||
$ go run .
|
$ go run .
|
||||||
$ go run . 50 12 4
|
2
|
||||||
|
6
|
||||||
|
7
|
||||||
|
1
|
||||||
$
|
$
|
||||||
```
|
```
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"piscine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(piscine.Gcd(42, 10))
|
||||||
|
fmt.Println(piscine.Gcd(42, 12))
|
||||||
|
fmt.Println(piscine.Gcd(14, 77))
|
||||||
|
fmt.Println(piscine.Gcd(17, 3))
|
||||||
|
}
|
Loading…
Reference in New Issue