tp1 exo7 + remove exit(0)
This commit is contained in:
parent
4a293ae154
commit
250a1552c0
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -13,5 +13,4 @@ int main() {
|
||||
printf("%d s'écrit binaire : ", x);
|
||||
f(x);
|
||||
printf("\n");
|
||||
exit(0);
|
||||
}
|
||||
|
@ -22,5 +22,4 @@ int main() {
|
||||
uint n = 32413524;
|
||||
printf("x = %d et n = %d\n", x, n);
|
||||
f(n, x);
|
||||
exit(0);
|
||||
}
|
||||
|
26
tp1/exo7.c
26
tp1/exo7.c
@ -1,17 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int f(int a, int b) {
|
||||
int i = 0;
|
||||
while (!((a % i == 0) && (b % i == 0))) {
|
||||
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);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void f(const char s[], char *ext) {
|
||||
uint i = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user