Skip to content

Commit 41d99e0

Browse files
authored
辗转相除法求最大公约数
1 parent 025e3ab commit 41d99e0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Greatest-Common-Divisor.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <cstdio>
2+
3+
using namespace std;
4+
5+
int gcd(int x, int y)
6+
{
7+
return x % y == 0 ? y : gcd(y, x % y);
8+
}
9+
10+
int main()
11+
{
12+
int a, b;
13+
while (true)
14+
{
15+
scanf("%d%d", &a, &b);
16+
printf("%d\n", gcd(a, b));
17+
}
18+
19+
return 0;
20+
}

0 commit comments

Comments
 (0)