Browse Source

gcd

pull/1/head
dewjjj 1 year ago
parent
commit
6a12c7ee4b
  1. 2
      README.md
  2. 19
      gcd/gcd.go

2
README.md

@ -13,4 +13,4 @@
|9|index0|指针案例一|
|10|flag0|flag包案例一|
|11|new|new函数案例一|
||||
|12|gcd|最大公约数|

19
gcd/gcd.go

@ -0,0 +1,19 @@
package main
import "fmt"
func main(){
var x,y int
fmt.Scanf("%d %d",&x,&y)
// fmt.Println(x,y)
// v := x%y
// fmt.Println(v)
res := gcd(x,y)
fmt.Println(res)
}
func gcd(x,y int) int {
for y!=0{
x,y = y,x%y
fmt.Println(x,y)
}
return x
}
Loading…
Cancel
Save