This commit is contained in:
Simoes Lukas 2024-10-01 15:08:29 +02:00
parent d674a59d0d
commit 471e4a7e75
3 changed files with 231 additions and 0 deletions

View File

@ -35,6 +35,7 @@ int main(void){
} }
printf("+\n"); printf("+\n");
/* Remplissage du tableau inverse */
for (i = 0; i != TAILLE_TABLEAU; i++) { for (i = 0; i != TAILLE_TABLEAU; i++) {
tab_inverse[i] = tab[TAILLE_TABLEAU-i-1]; tab_inverse[i] = tab[TAILLE_TABLEAU-i-1];
} }

View File

@ -0,0 +1,193 @@
-------- TP13 : Tableaux multidimensionnels --------
1.
# include <stdio.h>
# include <stdlib.h>
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 <stdio.h>
# include <stdlib.h>
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 <stdio.h>
# include <stdlib.h>
# 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;
}

37
DEV1.1/TP13/tests.c Normal file
View File

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