feat: Initial commit
This commit is contained in:
32
Laboratorio 2/esercizio1.c
Normal file
32
Laboratorio 2/esercizio1.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user