diff --git a/tp1/exo1.c b/tp1/exo1.c index f52a4a1..75c04b1 100644 --- a/tp1/exo1.c +++ b/tp1/exo1.c @@ -35,5 +35,4 @@ int main() { printf("Méthode iterative : %d^%d = %d\n", a, b, f_iter(a, b)); printf("Méthode recursive : %d^%d = %d\n", a, b, f_rec(a, b)); printf("Méthode d'exponentation rapide : %d^%d = %d\n", a, b, f_exp(a, b)); - exit(0); } diff --git a/tp1/exo2.c b/tp1/exo2.c index f501efa..b28e72f 100644 --- a/tp1/exo2.c +++ b/tp1/exo2.c @@ -14,5 +14,4 @@ int f(uint x) { return rec(0, x); } int main() { int x = 3459023; printf("Somme des chiffres de %d : %d", x, f(x)); - exit(0); } diff --git a/tp1/exo3.c b/tp1/exo3.c index 2a917dd..239f01d 100644 --- a/tp1/exo3.c +++ b/tp1/exo3.c @@ -25,5 +25,4 @@ int main() { uint k = 3; printf("Somme des puissances %d-ièmes des entiers de 1 à %d: %d", k, n, f(n, k)); - exit(0); } diff --git a/tp1/exo4.c b/tp1/exo4.c index 193b995..022d2e0 100644 --- a/tp1/exo4.c +++ b/tp1/exo4.c @@ -14,5 +14,4 @@ uint f(uint x) { return rec(0, x); } int main() { uint x = 8; printf("Nombre de chiffre de %d en binaire: %d", x, f(x)); - exit(0); } diff --git a/tp1/exo5.c b/tp1/exo5.c index 5cff6a3..e7a3c83 100644 --- a/tp1/exo5.c +++ b/tp1/exo5.c @@ -13,5 +13,4 @@ int main() { printf("%d s'écrit binaire : ", x); f(x); printf("\n"); - exit(0); } diff --git a/tp1/exo6.c b/tp1/exo6.c index 64cf4b6..8e1f1fd 100644 --- a/tp1/exo6.c +++ b/tp1/exo6.c @@ -22,5 +22,4 @@ int main() { uint n = 32413524; printf("x = %d et n = %d\n", x, n); f(n, x); - exit(0); } diff --git a/tp1/exo7.c b/tp1/exo7.c index dacabb2..3fb8fb1 100644 --- a/tp1/exo7.c +++ b/tp1/exo7.c @@ -1,17 +1,31 @@ #include #include -int f(int a, int b) { - int i = 0; - while (!((a % i == 0) && (b % i == 0))) { - i++; +uint ppcm(uint a, uint b) { + uint i = 2; + uint ppcm = 1; + while (a != 1 || b != 1) { + int da = a % i == 0; + int db = b % i == 0; + if (da) { + a /= i; + } + if (db) { + b /= i; + } + if (da || db) { + ppcm *= i; + } else { + i++; + } } - return i; + return ppcm; } +uint f(int a, int b) { return ppcm(abs(a), abs(b)); } + int main() { int a = 9; - int b = 73; + int b = -21; printf("ppcm(%d, %d) = %d\n", a, b, f(a, b)); - exit(0); } diff --git a/tp2/exo10.c b/tp2/exo10.c index 70ff976..214d47a 100644 --- a/tp2/exo10.c +++ b/tp2/exo10.c @@ -1,6 +1,5 @@ #include #include -#include void f(const char s[], char *ext) { uint i = 0;