public/subjects/gcd
nprimo 529e5c8fdb docs(gcd): update subject to require a function instead of a program
- add main.go to test the function in exam mode
2024-06-27 22:39:42 +01:00
..
README.md docs(gcd): update subject to require a function instead of a program 2024-06-27 22:39:42 +01:00
main.go docs(gcd): update subject to require a function instead of a program 2024-06-27 22:39:42 +01:00

README.md

gcd

Instructions

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.

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.

Expected function

func Gcd(a, b uint) uint {

}

Usage

Here is a possible program to test your function:

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 :

$ go run .
2
6
7
1
$