32 lines
503 B
C
32 lines
503 B
C
#include <stdio.h>
|
|
|
|
int mcd(int a, int b) {
|
|
if (a == 0) {
|
|
return b;
|
|
}
|
|
|
|
if (a > b) {
|
|
return mcd(a % b, b);
|
|
} else {
|
|
return mcd(b % a, a);
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int a, b, res;
|
|
if (scanf("%d %d", &a, &b) != 2) {
|
|
puts("Error, invalid input!");
|
|
return 1;
|
|
}
|
|
|
|
if (a < 0 || b < 0) {
|
|
puts("Error, you must insert two positive integers!");
|
|
return 1;
|
|
}
|
|
|
|
res = mcd(a, b);
|
|
printf("MCD = %d\n", res);
|
|
|
|
return 0;
|
|
} |