From 471e4a7e750c6f8aeb11eb7864f4d9ed95041eeb Mon Sep 17 00:00:00 2001 From: Simoes Lukas Date: Tue, 1 Oct 2024 15:08:29 +0200 Subject: [PATCH] TP 13 --- DEV1.1/TP12/tests.c | 1 + DEV1.1/TP13/TP13_reponses.txt | 193 ++++++++++++++++++++++++++++++++++ DEV1.1/TP13/tests.c | 37 +++++++ 3 files changed, 231 insertions(+) create mode 100644 DEV1.1/TP13/TP13_reponses.txt create mode 100644 DEV1.1/TP13/tests.c diff --git a/DEV1.1/TP12/tests.c b/DEV1.1/TP12/tests.c index f868c0a..58c2682 100644 --- a/DEV1.1/TP12/tests.c +++ b/DEV1.1/TP12/tests.c @@ -35,6 +35,7 @@ int main(void){ } printf("+\n"); + /* Remplissage du tableau inverse */ for (i = 0; i != TAILLE_TABLEAU; i++) { tab_inverse[i] = tab[TAILLE_TABLEAU-i-1]; } diff --git a/DEV1.1/TP13/TP13_reponses.txt b/DEV1.1/TP13/TP13_reponses.txt new file mode 100644 index 0000000..82c16c7 --- /dev/null +++ b/DEV1.1/TP13/TP13_reponses.txt @@ -0,0 +1,193 @@ +-------- TP13 : Tableaux multidimensionnels -------- + + +1. + +# include +# include + +int main(void) { + /* Déclaration des tableaux */ + int t1[2][5]; + int t2[3][5]; + int t3[5][5]; + int compteur; + /* Remplissage des tableaux */ + int i; + int j; + /* t1 */ + for (i = 0; i != 2; i++) { + for (j = 0; j != 5; j++) { + t1[i][j] = j + 1; + } + } + /* t2 */ + compteur = 1; + for (i = 0; i != 3; i++) { + for (j = 0; j != 5; j++) { + t2[i][j] = compteur; + compteur++; + } + } + /* t3 */ + compteur = 0; + for (i = 0; i != 5; i++) { + for (j = 0; j != 5; j++) { + if (j >= i) { + t3[i][j] = 0; + } + else { + t3[i][j] = 1 + j; + } + } + } + /* Affichage des tableaux */ + /* t1 */ + for (i = 0; i != 2; i++) { + for (j = 0; j != 5; j++) { + printf("%d ", t1[i][j]); + } + printf("\n"); + } + printf("\n"); + /* t2 */ + for (i = 0; i != 3; i++) { + for (j = 0; j != 5; j++) { + printf("%d ", t2[i][j]); + } + printf("\n"); + } + printf("\n"); + /* t3 */ + for (i = 0; i != 5; i++) { + for (j = 0; j != 5; j++) { + printf("%d ", t3[i][j]); + } + printf("\n"); + } + printf("\n"); + + /* Inversions lignes-colonnes */ + /* t1 */ + for (j = 0; j != 5; j++) { + for (i = 0; i != 2; i++) { + printf("%d ", t1[i][j]); + } + printf("\n"); + } + printf("\n"); + /* t2 */ + for (j = 0; j != 5; j++) { + for (i = 0; i != 3; i++) { + printf("%d ", t2[i][j]); + } + printf("\n"); + } + printf("\n"); + /* t3 */ + for (j = 0; j != 5; j++) { + for (i = 0; i != 5; i++) { + printf("%d ", t3[i][j]); + } + printf("\n"); + } + printf("\n"); + + return EXIT_SUCCESS; +} + + +2. + +# include +# include + +int main(void) { + /* Déclaration des tableaux */ + int t1[2][5]; + int t2[3][5]; + int t3[5][5]; + int compteur; + /* Remplissage des tableaux */ + int i; + int j; + int k; + int nb_lignes; + /* t1 */ + for (i = 0; i != 2; i++) { + for (j = 0; j != 5; j++) { + t1[i][j] = j + 1; + } + } + /* t2 */ + compteur = 1; + for (i = 0; i != 3; i++) { + for (j = 0; j != 5; j++) { + t2[i][j] = compteur; + compteur++; + } + } + /* t3 */ + for (i = 0; i != 5; i++) { + for (j = 0; j != 5; j++) { + if (j >= i) { + t3[i][j] = 0; + } + else { + t3[i][j] = 1 + j; + } + } + } + /* Affichage des tableaux */ + nb_lignes = 2 + for (i = 0; i != 3; i++) { + for (j = 0; j != 5; j++) { + for (k = 0; k != 2; k++) { + /* TO DO */ + } + } + } + + return EXIT_SUCCESS; +} + + +3. + +# include +# include +# define HAUTEUR 30 + +int main(void) { + int t[HAUTEUR][HAUTEUR]; + /* Création du triangle de Pascal */ + int k; + int n; + for (k = 0; k != HAUTEUR; k++) { + for (n = 0; n != HAUTEUR; n++) { + if (k == n && k >= 0) { + t[k][n] = 1; + } + else if (k > n && n >= 1) { + t[k][n] = t[k-1][n] + t[k-1][n-1]; + } + else if (k>=0 && n == 0) { + t[k][n] = 1; + } + else { + t[k][n] = 0; + } + } + } + /* Affichage */ + for (k = 0; k != HAUTEUR; k++) { + for (n = 0; n != HAUTEUR; n++) { + if (t[k][n] != 0) { + printf("%d ", t[k][n]); + } + } + printf("\n"); + } + printf("\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/DEV1.1/TP13/tests.c b/DEV1.1/TP13/tests.c new file mode 100644 index 0000000..c0aa7af --- /dev/null +++ b/DEV1.1/TP13/tests.c @@ -0,0 +1,37 @@ +# include +# include +# define HAUTEUR 30 + +int main(void) { + int t[HAUTEUR][HAUTEUR]; + /* Création du triangle de Pascal */ + int k; + int n; + for (k = 0; k != HAUTEUR; k++) { + for (n = 0; n != HAUTEUR; n++) { + if (k == n && k >= 0) { + t[k][n] = 1; + } + else if (k > n && n >= 1) { + t[k][n] = t[k-1][n] + t[k-1][n-1]; + } + else if (k>=0 && n == 0) { + t[k][n] = 1; + } + else { + t[k][n] = 0; + } + } + } + /* Affichage */ + for (k = 0; k != HAUTEUR; k++) { + for (n = 0; n != HAUTEUR; n++) { + if (t[k][n] != 0) { + printf("%d ", t[k][n]); + } + } + printf("\n"); + } + printf("\n"); + return EXIT_SUCCESS; +} \ No newline at end of file