diff --git a/DEV1.1/TP15/TP15_reponses.txt b/DEV1.1/TP15/TP15_reponses.txt new file mode 100644 index 0000000..0e8be97 --- /dev/null +++ b/DEV1.1/TP15/TP15_reponses.txt @@ -0,0 +1,32 @@ +------- TP15 : Chaînes de caractères ------- + +1. + +2. + +3. + +# include +# include + +int main(int argc, char** argv){ + int compteur; + compteur = 0; + for (; argc != 0; argc--) { + printf("%c ", argv[compteur][0]); + compteur++; + } + printf("\n"); +} + +4. +TO DO + +# include +# include +# include +# define TAILLE 26 + +int main(int argc, char** argv){ + printf("%d", (int) argv[0] * (int) argv[1]); +} \ No newline at end of file diff --git a/DEV1.1/TP15/tests.c b/DEV1.1/TP15/tests.c new file mode 100644 index 0000000..7a35cbf --- /dev/null +++ b/DEV1.1/TP15/tests.c @@ -0,0 +1,8 @@ +# include +# include +# include +# define TAILLE 26 + +int main(int argc, char** argv){ + printf("%d", (int) argv[0] * (int) argv[1]); +} \ No newline at end of file diff --git a/DEV1.1/TP16/TP16_reponses.txt b/DEV1.1/TP16/TP16_reponses.txt new file mode 100644 index 0000000..02b5412 --- /dev/null +++ b/DEV1.1/TP16/TP16_reponses.txt @@ -0,0 +1,188 @@ +------ TP16 : Fonctions ----- + +1. + +# include +# include + + +void triangle(int hauteur) { + int i; + int j; + for (i = 0; i != hauteur; i++) { + for (j = 0; j != i+1; j++) { + putchar('*'); + } + putchar('\n'); + } +} + + +void carre(int hauteur) { + int i; + int j; + for (i = 0; i != hauteur; i++) { + putchar('*'); + } + putchar('\n'); + for (j = 0; j != hauteur-2; j++) { + for (i = 0; i != hauteur; i++) { + if (i == 0 || i == hauteur-1) { + putchar('*'); + } + else { + putchar(' '); + } + } + putchar('\n'); + } + for (i = 0; i != hauteur; i++) { + putchar('*'); + } +} + + +void menu(void) { + char selection; + int hauteur; + printf("\n__________\n t) Triangle\n c) Carré\n q) Quitter\nVotre choix ? "); + scanf("%c", &selection); + getchar(); + if (selection == 'q') { + return; + } + printf("\nHauteur ?"); + scanf("%d", &hauteur); + getchar(); + if (selection == 't') { + triangle(hauteur); + menu(); + return; + } + if (selection == 'c') { + carre(hauteur); + menu(); + } + else { + menu(); + return; + } +} + + +int main(void) { + menu(); + return EXIT_SUCCESS; +} + + +2. + +# include +# include +# include +# define TAILLE_TABLEAU 10 + + +void remplissage(int* tab, int tab_len) { + int i; + for (i = 0; i != tab_len; i++) { + tab[i] = (rand() % 100) - 50; + } +} + + +void affichage(int* tab, int tab_len) { + int i; + for (i = 0; i != tab_len; i++) { + printf("+-----"); + } + printf("+\n"); + for (i = 0; i != tab_len; 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 != tab_len; i++) { + printf("+-----"); + } + printf("+\n"); +} + + +void remplissage_inverse(int* tab, int* tab_inverse, int tab_len) { + int i; + for (i = 0; i != tab_len; i++) { + tab_inverse[i] = tab[tab_len-i-1]; + } +} + + +int main(void){ + int tab[TAILLE_TABLEAU]; + int tab_inverse[TAILLE_TABLEAU]; + srand(time(NULL)); + remplissage(tab, TAILLE_TABLEAU); + affichage(tab, TAILLE_TABLEAU); + remplissage_inverse(tab, tab_inverse, TAILLE_TABLEAU); + affichage(tab_inverse, TAILLE_TABLEAU); + return EXIT_SUCCESS; +} + + +3. La fonction ne fait pas son travail car elle ne modifie la variable a que dans le bloc +de la fonction. Il faut donc la renvoyer et assigner à la variable x la valeur renvoyée +par la fonction zero() : + + +# include +# include + + +double zero(double a) { + a = 0.0; + return a; +} + + +int main(void) { + double x=37.5; + printf("avant : %f\n", x); + x = zero(x); + printf("après : %f\n", x); + return EXIT_SUCCESS; +} + + +4. + +PAS FINI + +# include +# include + + +void inverse_variables(int a, int b) { + int temp; + temp = a; + a = &b; + b = &temp; +} + + +int main(void) { + int x, y; + x = 12; + y = 5; + printf("avant : x = %d y = %d\n", x, y); + inverse_variables(x, y); + printf("avant : x = %d y = %d\n", x, y); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP16/tests.c b/DEV1.1/TP16/tests.c new file mode 100644 index 0000000..c9bbad8 --- /dev/null +++ b/DEV1.1/TP16/tests.c @@ -0,0 +1,22 @@ + +# include +# include + + +void inverse_variables(int a, int b) { + int temp; + temp = a; + a = &b; + b = &temp; +} + + +int main(void) { + int x, y; + x = 12; + y = 5; + printf("avant : x = %d y = %d\n", x, y); + inverse_variables(x, y); + printf("avant : x = %d y = %d\n", x, y); + return EXIT_SUCCESS; +} \ No newline at end of file