Compare commits
4 commits
6c2b2b8dcd
...
3034d88603
Author | SHA1 | Date | |
---|---|---|---|
|
3034d88603 | ||
|
34f6792698 | ||
|
e7efbd99c5 | ||
|
73ed29058b |
77
DS2-2015/E3.c
Normal file
77
DS2-2015/E3.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/* Valeurs approchées d'intégrales */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
double f(double x) {
|
||||
return exp(2*x) + log(x + 1);
|
||||
}
|
||||
|
||||
// 1)
|
||||
|
||||
int main1(int argc, char *argv[]) {
|
||||
int n = 100;
|
||||
double a = 0;
|
||||
double b = 1;
|
||||
double h = (b - a) / n;
|
||||
|
||||
|
||||
// Ici I0s et I1s sont les valeurs approchées
|
||||
double I0s = 0;
|
||||
double I1s = 0;
|
||||
int i;
|
||||
// x_i = h * i
|
||||
for (i = 0; i < n; i++) {
|
||||
I0s += (h/2)*(f(h*i)+f(h*(i+1)));
|
||||
I1s += (h/6)*(f(h*i)+4*f(h*i+(h/2)+f(h*(i+1))));
|
||||
}
|
||||
printf("I0 = %lf\n", I0s);
|
||||
printf("I1 = %lf\n", I1s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 2)
|
||||
|
||||
// Ici I0 et I1 sont des fonctions calculant un élément de la somme pour un x_i donné
|
||||
double I0(double (*Pf)(double x), double a, double h) {
|
||||
return (h/2) * ((*Pf)(a) + (*Pf)(a+h));
|
||||
}
|
||||
|
||||
double I1(double (*Pf)(double x), double a, double h) {
|
||||
return (h/6) * ((*Pf)(a) + 4*(*Pf)(a+(h/2)) + (*Pf)(a+h));
|
||||
}
|
||||
|
||||
double (*integ[2])(double (*Pf)(double x), double a, double h) = {I0, I1};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Intervalle d'intégration
|
||||
double a;
|
||||
printf("a = ");
|
||||
scanf("%lf", &a);
|
||||
double b;
|
||||
printf("b = ");
|
||||
scanf("%lf", &b);
|
||||
// Nombre de pas d'intégration
|
||||
int n;
|
||||
printf("n = ");
|
||||
scanf("%d", &n);
|
||||
double h = (b - a) / n;
|
||||
|
||||
// On choisit ici la fonction qu'on veut tester
|
||||
double (*Pf)(double x) = f;
|
||||
|
||||
// Ici I0s et I1s sont les valeurs approchées
|
||||
double I0s = 0;
|
||||
double I1s = 0;
|
||||
int i;
|
||||
// x_i = h * i
|
||||
for (i = 0; i < n; i++) {
|
||||
I0s += integ[0](Pf, h*i, h);
|
||||
I1s += integ[1](Pf, h*i, h);
|
||||
}
|
||||
printf("I0 = %lf\n", I0s);
|
||||
printf("I1 = %lf\n", I1s);
|
||||
|
||||
}
|
27
TP4/E4.c
Normal file
27
TP4/E4.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Comparaison de deux tableaux d'entiers */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
int T1[] = {12, 23, 34, 45, 56, 67, 78, 89, 90};
|
||||
int T2[] = {12, 23, 34, 45, 56, 67, 78, 89, 90};
|
||||
|
||||
|
||||
if (sizeof(T1) != sizeof(T2)) {
|
||||
printf("Les tableaux ne sont pas de la même taille.\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
int n = sizeof(T1)/sizeof(int);
|
||||
int *P1, *P2;
|
||||
for (P1 = T1, P2 = T2; P1 < T1 + n; P1++, P2++) {
|
||||
if (*P1 != *P2) {
|
||||
printf("Les tableaux diffèrent.\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
printf("Les tableaux sont identiques.\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
return 0;
|
||||
}
|
22
TP4/E5.c
Normal file
22
TP4/E5.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* Recherche de la valeur minimale */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int T[] = {90, 23, 34, 10, 56, 67, 78, 89, 12};
|
||||
int deb = 0;
|
||||
int fin = 8;
|
||||
|
||||
int *P, *minI = T + deb, min = *(minI);
|
||||
for (P = T + deb; P <= T + fin; P++) {
|
||||
if (*P < min) {
|
||||
min = *P;
|
||||
minI = P;
|
||||
}
|
||||
}
|
||||
printf("La valeur minimum est %d et est à l'indice %d.\n", min, minI-T);
|
||||
|
||||
return 0;
|
||||
}
|
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