diff --git a/DEV1.1/TP11/TP11_reponses.txt b/DEV1.1/TP11/TP11_reponses.txt new file mode 100644 index 0000000..db00397 --- /dev/null +++ b/DEV1.1/TP11/TP11_reponses.txt @@ -0,0 +1,85 @@ +-------- TP11 : Math -------- + +1. + +# include +# include +# include +# define M_PI 3.14159265358979323846264338379 + +int main(void) { + printf("%f\n", sqrt(fabs(log(0.5)))); + printf("%f\n", sin(M_PI/6.0)); + printf("%f\n", atan(pow(13.0, 2.0))); + printf("%f\n", pow(exp(-1.0), 4.0)); + printf("%f\n", log(-3.0)); + printf("%f\n", pow(sqrt(2.0), 2.0)); + return EXIT_SUCCESS; +} + + +2. + +# include +# include +# include +# define M_PI 3.14159265358979323846264338379 + +int main(void) { + double xa; + double xb; + double ya; + double yb; + printf("Entrez xa : "); + scanf("%lf", &xa); + getchar(); + printf("\nEntrez xb : "); + scanf("%lf", &xb); + getchar(); + printf("\nEntrez ya : "); + scanf("%lf", &ya); + getchar(); + printf("\nEntrez yb : "); + scanf("%lf", &yb); + getchar(); + printf("Distance : %f", sqrt(pow((ya - xa), 2.0) + pow((yb - ya), 2.0))); + return EXIT_SUCCESS; +} + + +3. + +# include +# include +# include +# define M_PI 3.14159265358979323846264338379 + +int main(void) { + double rayon; + double angle; + printf("Entrez rayon : "); + scanf("%lf", &rayon); + getchar(); + printf("\nEntrez angle (en rad) : "); + scanf("%lf", &angle); + getchar(); + printf("x : %f ; y : %f", rayon*cos(angle), rayon*sin(angle)); + return EXIT_SUCCESS; +} + + +4. + +# include +# include +# include +# define M_PI 3.14159265358979323846264338379 + +int main(void) { + double reel; + printf("Entrez un réel : "); + scanf("%lf", &reel); + printf("chiffre des unités : %d\n", (int) floor(reel) % 10); + printf("chiffre des dixièmes : %d\n", (int) floor(reel * 10) % 10); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP11/tests.c b/DEV1.1/TP11/tests.c new file mode 100644 index 0000000..b622b7e --- /dev/null +++ b/DEV1.1/TP11/tests.c @@ -0,0 +1,13 @@ +# include +# include +# include +# define M_PI 3.14159265358979323846264338379 + +int main(void) { + double reel; + printf("Entrez un réel : "); + scanf("%lf", &reel); + printf("chiffre des unités : %d\n", (int) floor(reel) % 10); + printf("chiffre des dixièmes : %d\n", (int) floor(reel * 10) % 10); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP12/TP12_reponses.txt b/DEV1.1/TP12/TP12_reponses.txt new file mode 100644 index 0000000..58e4fff --- /dev/null +++ b/DEV1.1/TP12/TP12_reponses.txt @@ -0,0 +1,231 @@ +------- TP12 : Tableaux ------- + +1. + +# include +# include +# include +# define TAILLE_TABLEAU 10 + +int main(void){ + int tab[TAILLE_TABLEAU]; + int i; + srand(time(NULL)); + + /* Remplissage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + tab[i] = (rand() % 100) - 50; + } + /* Affichage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + if (tab[i] < 10 && tab[i] >= 0) { + printf("| %d ", tab[i]); + } + else if (tab[i] < -9) { + printf("| %d ", tab[i]); + } + else { + printf("| %d ", tab[i]); + } + } + printf("|\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + + return EXIT_SUCCESS; +} + + +2. + +# include +# include +# include +# define TAILLE_TABLEAU 10 + +int main(void){ + int tab[TAILLE_TABLEAU]; + int i; + int maxi; + int indice_max; + srand(time(NULL)); + + /* Remplissage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + tab[i] = (rand() % 100) - 50; + } + + /* Recherche du maximum */ + maxi = tab[0]; + indice_max = 0; + for (i = 0; i != TAILLE_TABLEAU; i++) { + if (tab[i] > maxi) { + maxi = tab[i]; + indice_max = i; + } + } + /* Affichage du maximum */ + for (i = 0; i != (indice_max*6) + 3; i++) { + printf(" "); + } + printf("|\n"); + for (i = 0; i != (indice_max*6) + 3; i++) { + printf(" "); + } + printf("V\n"); + + /* Affichage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + if (tab[i] < 10 && tab[i] >= 0) { + printf("| %d ", tab[i]); + } + else if (tab[i] < -9) { + printf("| %d ", tab[i]); + } + else { + printf("| %d ", tab[i]); + } + } + printf("|\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + + return EXIT_SUCCESS; +} + +3. + +# include +# include +# include +# define TAILLE_TABLEAU 10 + +int main(void){ + int tab[TAILLE_TABLEAU]; + int i; + int recherche; + int indice_recherche; + srand(time(NULL)); + + /* Remplissage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + tab[i] = (rand() % 100) - 50; + } + /* Affichage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + if (tab[i] < 10 && tab[i] >= 0) { + printf("| %d ", tab[i]); + } + else if (tab[i] < -9) { + printf("| %d ", tab[i]); + } + else { + printf("| %d ", tab[i]); + } + } + printf("|\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + + /* Recherche d'indice par l'utilisateur */ + printf("Quelle valeur chercher ? "); + scanf("%d",&recherche); + indice_recherche = -1; + for (i = 0; i != TAILLE_TABLEAU; i++) { + if (tab[i] == recherche && indice_recherche == -1) { + indice_recherche = i; + } + } + printf("\n%d\n", indice_recherche); + + + return EXIT_SUCCESS; +} + + +4. + +# include +# include +# include +# define TAILLE_TABLEAU 10 + +int main(void){ + int tab[TAILLE_TABLEAU]; + int tab_inverse[TAILLE_TABLEAU]; + int i; + srand(time(NULL)); + + /* Remplissage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + tab[i] = (rand() % 100) - 50; + } + /* Affichage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + if (tab[i] < 10 && tab[i] >= 0) { + printf("| %d ", tab[i]); + } + else if (tab[i] < -9) { + printf("| %d ", tab[i]); + } + else { + printf("| %d ", tab[i]); + } + } + printf("|\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + + /* Remplissage du tableau inverse */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + tab_inverse[i] = tab[TAILLE_TABLEAU-i-1]; + } + + /* Affichage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + if (tab_inverse[i] < 10 && tab_inverse[i] >= 0) { + printf("| %d ", tab_inverse[i]); + } + else if (tab_inverse[i] < -9) { + printf("| %d ", tab_inverse[i]); + } + else { + printf("| %d ", tab_inverse[i]); + } + } + printf("|\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + + return EXIT_SUCCESS; +} diff --git a/DEV1.1/TP12/tests.c b/DEV1.1/TP12/tests.c new file mode 100644 index 0000000..f868c0a --- /dev/null +++ b/DEV1.1/TP12/tests.c @@ -0,0 +1,65 @@ +# include +# include +# include +# define TAILLE_TABLEAU 10 + +int main(void){ + int tab[TAILLE_TABLEAU]; + int tab_inverse[TAILLE_TABLEAU]; + int i; + srand(time(NULL)); + + /* Remplissage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + tab[i] = (rand() % 100) - 50; + } + /* Affichage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + if (tab[i] < 10 && tab[i] >= 0) { + printf("| %d ", tab[i]); + } + else if (tab[i] < -9) { + printf("| %d ", tab[i]); + } + else { + printf("| %d ", tab[i]); + } + } + printf("|\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + + for (i = 0; i != TAILLE_TABLEAU; i++) { + tab_inverse[i] = tab[TAILLE_TABLEAU-i-1]; + } + + /* Affichage du tableau */ + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + if (tab_inverse[i] < 10 && tab_inverse[i] >= 0) { + printf("| %d ", tab_inverse[i]); + } + else if (tab_inverse[i] < -9) { + printf("| %d ", tab_inverse[i]); + } + else { + printf("| %d ", tab_inverse[i]); + } + } + printf("|\n"); + for (i = 0; i != TAILLE_TABLEAU; i++) { + printf("+-----"); + } + printf("+\n"); + + return EXIT_SUCCESS; +}