Fin du TP12

This commit is contained in:
Simoes Lukas 2024-09-30 15:02:16 +02:00
parent bda03135c6
commit d674a59d0d
4 changed files with 394 additions and 0 deletions

View File

@ -0,0 +1,85 @@
-------- TP11 : Math --------
1.
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# 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 <stdio.h>
# include <stdlib.h>
# include <math.h>
# 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 <stdio.h>
# include <stdlib.h>
# include <math.h>
# 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 <stdio.h>
# include <stdlib.h>
# include <math.h>
# 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;
}

13
DEV1.1/TP11/tests.c Normal file
View File

@ -0,0 +1,13 @@
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# 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;
}

View File

@ -0,0 +1,231 @@
------- TP12 : Tableaux -------
1.
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
# 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 <stdio.h>
# include <stdlib.h>
# include <time.h>
# 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 <stdio.h>
# include <stdlib.h>
# include <time.h>
# 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 <stdio.h>
# include <stdlib.h>
# include <time.h>
# 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;
}

65
DEV1.1/TP12/tests.c Normal file
View File

@ -0,0 +1,65 @@
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
# 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;
}