Skip to content

Commit abb697f

Browse files
rmoreirat2013anurag
authored andcommitted
adding go code for calculating gcd (#1052)
1 parent 567242c commit abb697f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

gcd/go/gcd.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func gcd(a, b int) int {
6+
if b == 0 {
7+
return a
8+
} else {
9+
return gcd(b, a%b)
10+
}
11+
}
12+
13+
func main() {
14+
fmt.Println("Please provide 2 numbers")
15+
fmt.Print("First number: ")
16+
var a int
17+
fmt.Scan(&a)
18+
fmt.Print("Second number: ")
19+
var b int
20+
fmt.Scan(&b)
21+
fmt.Printf("gcd(%d,%d)=%d\n", a, b, gcd(a, b))
22+
}

0 commit comments

Comments
 (0)