1.辗转相除法
#include<stdio.h>
int main()
{
int m = 0;
int n = 0;
int j = 0;
scanf("%d %d", &n, &m);
while (m%n)
{
j = m % n;
n = j;
m = n;
}
printf("%d", n);
return 0;
}
2. 辗转相减法
#include<stdio.h>
int main()
{
int a = 0;
int b = 0;
scanf("%d%d", &a, &b);
while (a != b)
{
if (a > b)
{
a = a - b;
}
if (a < b)
{
b = b - a;
}
}
printf("%d", a);
return 0;
}