Files
Laboratori-TDP/Laboratorio 2/esercizio1.c
2024-03-22 17:14:57 +01:00

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;
}