diff --git a/TP4/E6.c b/TP4/E6.c new file mode 100644 index 0000000..3026456 --- /dev/null +++ b/TP4/E6.c @@ -0,0 +1,36 @@ +/* Tri */ + +#include +#include +#include + +int main(int argc, char *argv[]) { + int n, *P1, *P2, min, *minP; + printf("Saississez la taille du tableau : "); + scanf("%d", &n); + + int T[n]; + for (P1 = T; P1 < T+n; P1++) { + printf("T[%d] = ", P1-T); + scanf("%d", P1); + } + + for (P1 = T; P1 < T+n; P1++) { + for (P2 = P1; P2 < T+n; P2++) { + if (*P2 < min || P2 == P1) { + min = *P2; + minP = P2; + } + } + *minP = *P1; + *P1 = min; + } + + // Affichage + for (P1 = T; P1 < T+n; P1++) { + printf("%d, ", *P1); + } + printf("\n"); + + return 0; +} diff --git a/TP5/E1.c b/TP5/E1.c new file mode 100644 index 0000000..162b275 --- /dev/null +++ b/TP5/E1.c @@ -0,0 +1,28 @@ +/* Composition de fonctions */ + +#include +#include +#include + +double f(double x) { + return pow(x, 3) + 2 * pow(x, 2) + 3 * x - 4; +} + +double g(double x) { + return 1 - x; +} + +double composition(double(*Pf)(double x), double(*Pg)(double x), double x) { + return (*Pf)((*Pg)(x)); +} + +int main(int argc, char *argv[]) { + double(*Pf)(double x) = &f; + double(*Pg)(double x) = &g; + double a = -1; + printf("fog(%lf) = %lf\n", a, composition(Pf, Pg, a)); + printf("gof(%lf) = %lf\n", a, composition(Pg, Pf, a)); + printf("fof(%lf) = %lf\n", a, composition(Pf, Pf, a)); + printf("gog(%lg) = %lg\n", a, composition(Pg, Pg, a)); + return 0; +} diff --git a/TP5/Makefile b/TP5/Makefile new file mode 100644 index 0000000..82754c0 --- /dev/null +++ b/TP5/Makefile @@ -0,0 +1,9 @@ +all: $(patsubst %.c,%.exe,$(shell ls *.c)) + +%.exe: %.c + gcc -g $< -o $@ -lm + +.PHONY: all clean + +clean: + rm *.exe