TP12 Tableaux Multidimensionnels

This commit is contained in:
HORVILLE 2021-10-05 16:18:00 +02:00
parent 463951927a
commit 693923722b
5 changed files with 171 additions and 0 deletions

19
APL1.1/TP12/balayage.c Normal file
View File

@ -0,0 +1,19 @@
#include<stdio.h>
#include<stdlib.h>
//A ignorer, incomplet.
int main(int argc, char * argv[]) {
int table[450] = {}
table[0] = 1;
table[1] = 1;
table[2] = 1;
for (int i = 3; i < 900; i++) {
}
return EXIT_SUCCESS;
}

46
APL1.1/TP12/horizontal.c Normal file
View File

@ -0,0 +1,46 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[]) {
int table1[2][5] = {};
int table2[3][5] = {};
int table3[5][5] = {};
for (int i = 0; i < 5; i++) {
table1[0][i] = i+1;
table1[1][i] = i+1;
}
for (int i = 0; i < 15; i++) {
table2[i/5][i%5] = i+1;
}
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (y < x) table3[x][y] = y+1;
else table3[x][y] = 0;
}
}
for (int l = 0; l < 5; l++) {
for (int c = 0; c < 17; c++) {
if (l < 1) {
if (c < 5) printf("%2d ", table1[l][c]);
else if (c > 5 && c < 11) printf("%2d ", table2[l][c-6]);
else if (c > 11) printf("%2d ", table3[l][c-12]);
else printf(" ");
} else if (l < 2) {
if (c > 5 && c < 11) printf("%2d ", table2[l][c-6]);
else if (c > 11) printf("%2d ", table3[l][c-12]);
else printf(" ");
} else {
if (c > 11) printf("%2d ", table3[l][c-12]);
else printf(" ");
}
}
printf("\n");
}
return EXIT_SUCCESS;
}

32
APL1.1/TP12/magique.c Normal file
View File

@ -0,0 +1,32 @@
#include<stdio.h>
#include<stdlib.h>
//Incomplet.
void show2dtable(int l, int c, int table[][5]) {
for (int line = 0; line < (l*2)+1; line++) {
if (line == 0 || line == (l*2)+1 || line % 2 == 0) {
for (int col = 0; col < c; col++) printf("+-----");
printf("+\n");
} else {
for (int col = 0; col < c; col++) printf("| %3d ", table[line/2][col]);
printf("|\n");
}
}
}
int main(int argc, char * argv[]) {
int numcheck[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int carre[3][3] = {};
for (int i = 0; i < 9; i ++) {
printf("Valeur case n°%d : ", i+1);
scanf("%d", carre[i%3][i/3]);
}
for (int i = 0; i < 9; i++) {
if ()
}
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,45 @@
#include<stdio.h>
#include<stdlib.h>
//Affiche un tableau 2D, donnez la longueur / hauteur du tableau et il l'affichera
void show2dtable(int l, int c, int table[][5]) {
for (int line = 0; line < (l*2)+1; line++) {
if (line == 0 || line == (l*2)+1 || line % 2 == 0) {
for (int col = 0; col < c; col++) printf("+-----");
printf("+\n");
} else {
for (int col = 0; col < c; col++) printf("| %3d ", table[line/2][col]);
printf("|\n");
}
}
}
int main(int argc, char * argv[]) {
int table1[2][5] = {};
int table2[3][5] = {};
int table3[5][5] = {};
for (int i = 0; i < 5; i++) {
table1[0][i] = i+1;
table1[1][i] = i+1;
}
for (int i = 0; i < 15; i++) {
table2[i/5][i%5] = i+1;
}
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
if (y < x) table3[x][y] = y+1;
else table3[x][y] = 0;
}
}
show2dtable(2, 5, table1);
printf("\n");
show2dtable(3, 5, table2);
printf("\n");
show2dtable(5, 5, table3);
return EXIT_SUCCESS;
}

29
APL1.1/TP12/triangle.c Normal file
View File

@ -0,0 +1,29 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[]) {
int table[30][30] = {};
for (int x = 0; x < 30; x++) {
for (int y = 0; y < 30; y++) {
if (y == 0 || y == x) table[x][y] = 1; else table[x][y] = 0;
}
}
for (int l = 1; l < 30; l++) {
for (int c = 1; c < l; c++) {
int t1 = table[l-1][c-1];
int t2 = table[l-1][c];
table[l][c] = t1 + t2;
}
}
for (int l = 0; l < 15; l++) {
for (int c = 0; c <= l; c++) {
printf("%4d ", table[l][c]);
}
printf("\n");
}
return EXIT_SUCCESS;
}