Skip to content

Commit a753757

Browse files
committed
Adde Euclid
1 parent e4df694 commit a753757

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Euclid/euclid.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
// calculates
8+
func euclid(a, b int) int {
9+
if b == 0 {
10+
return a
11+
}
12+
return euclid(b, a%b) // recursive call
13+
}
14+
15+
func main() {
16+
const text = "Least common multiple of"
17+
x, y := 65, 26
18+
fmt.Printf("%s %d and %d = %d\n", text, x, y, euclid(x, y))
19+
x, y = 224, 12
20+
fmt.Printf("%s %d and %d = %d\n", text, x, y, euclid(x, y))
21+
x, y = 1605, 24
22+
fmt.Printf("%s %d and %d = %d\n", text, x, y, euclid(x, y))
23+
x, y = 77, 392
24+
fmt.Printf("%s %d and %d = %d\n", text, x, y, euclid(x, y))
25+
x, y = 109, 15
26+
fmt.Printf("%s %d and %d = %d\n", text, x, y, euclid(x, y))
27+
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
* GenericStack: a stack (LIFO collection) that can hold values of any type
88

99
*Level: Beginner*
10+
11+
* Euclid: a recursive algorithm to find the least common multiple
12+
13+
*Level: Beginner*

0 commit comments

Comments
 (0)