TP5 E1
This commit is contained in:
parent
e7efbd99c5
commit
34f6792698
36
TP4/E6.c
Normal file
36
TP4/E6.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* Tri */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
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;
|
||||
}
|
28
TP5/E1.c
Normal file
28
TP5/E1.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* Composition de fonctions */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
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;
|
||||
}
|
9
TP5/Makefile
Normal file
9
TP5/Makefile
Normal file
|
@ -0,0 +1,9 @@
|
|||
all: $(patsubst %.c,%.exe,$(shell ls *.c))
|
||||
|
||||
%.exe: %.c
|
||||
gcc -g $< -o $@ -lm
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
clean:
|
||||
rm *.exe
|
Reference in a new issue