diff --git a/APL1.1/TP11/circulation.c b/APL1.1/TP11/circulation.c new file mode 100644 index 0000000..45e65d3 --- /dev/null +++ b/APL1.1/TP11/circulation.c @@ -0,0 +1,41 @@ +#include +#include +#include + +#define DECALAGE 4 + +void showtable(int tablesize, int* table) { + for (int i = 0; i < tablesize; i++) printf("+-----"); + printf("+\n"); + + for (int i = 0; i < tablesize; i++) printf("| %3d ", table[i]); + printf("|\n"); + + for (int i = 0; i < tablesize; i++) printf("+-----"); + printf("+\n"); +} + +int main(int argc, char * argv[]) { + int tab[10] = {}; + + srand(time(NULL)); + int rand_v = rand(); + + for (int i = 0; i < 10; i++) { + srand(rand_v); + tab[i] = rand() % 101 > 50 ? (-rand() % 100) + 50: (rand() % 100) - 50; + rand_v = rand(); + } + + showtable(10, tab); + + int tab2[10] = {}; + for (int i = 0; i < 10; i++) { + int i2 = (i+DECALAGE) % 10; + tab2[i2] = tab[i]; + } + + showtable(10, tab2); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP11/filtre.c b/APL1.1/TP11/filtre.c new file mode 100644 index 0000000..191e4f8 --- /dev/null +++ b/APL1.1/TP11/filtre.c @@ -0,0 +1,45 @@ +#include +#include +#include + +void showtable(int tablesize, int* table) { + for (int i = 0; i < tablesize; i++) printf("+-----"); + printf("+\n"); + + for (int i = 0; i < tablesize; i++) printf("| %3d ", table[i]); + printf("|\n"); + + for (int i = 0; i < tablesize; i++) printf("+-----"); + printf("+\n"); +} + +void showtable2(int tablesize, int* table) { + for (int i = 0; i < tablesize; i++) if (table[i] >= 0) printf("+-----"); + printf("+\n"); + + for (int i = 0; i < tablesize; i++) if (table[i] >= 0) printf("| %3d ", table[i]); + printf("|\n"); + + for (int i = 0; i < tablesize; i++) if (table[i] >= 0) printf("+-----"); + printf("+\n"); +} + +int main(int argc, char * argv[]) { + int tab[10] = {}; + + srand(time(NULL)); + int rand_v = rand(); + + for (int i = 0; i < 10; i++) { + srand(rand_v); + tab[i] = rand() % 101 > 50 ? (-rand() % 100) + 50: (rand() % 100) - 50; + rand_v = rand(); + } + + showtable(10, tab); + printf("\n\n"); + + showtable2(10, tab); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP11/maximum.c b/APL1.1/TP11/maximum.c new file mode 100644 index 0000000..224ca46 --- /dev/null +++ b/APL1.1/TP11/maximum.c @@ -0,0 +1,49 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + int tab[10] = {}; + + srand(time(NULL)); + int rand_v = rand(); + int max = -50; + + //Génération des valeurs aléatoires et détection du maximum. + for (int i = 0; i < 10; i++) { + srand(rand_v); + tab[i] = rand() % 101 > 50 ? (-rand() % 100) + 50: (rand() % 100) - 50; + rand_v = rand(); + + max = max < tab[i] ? tab[i] : max; + } + + //Placement de la flèche à l'endroit du maximum + for (int i = 0; i <= 10; i++) { + if (tab[i] != max) { + printf(" "); + } else { + printf(" V\n"); + break; + } + } + + //Génération du tableau (visuellement) + for (int i = 0; i < 10; i++) { + printf("+-----"); + } + printf("+\n"); + + for (int i = 0; i < 10; i++) { + printf("| %3d ", tab[i]); + } + printf("|\n"); + + for (int i = 0; i < 10; i++) { + printf("+-----"); + } + printf("+\n"); + + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP11/miroir.c b/APL1.1/TP11/miroir.c new file mode 100644 index 0000000..b649ee2 --- /dev/null +++ b/APL1.1/TP11/miroir.c @@ -0,0 +1,40 @@ +#include +#include +#include + +void showtable(int tablesize, int* table) { + for (int i = 0; i < tablesize; i++) printf("+-----"); + printf("+\n"); + + for (int i = 0; i < tablesize; i++) printf("| %3d ", table[i]); + printf("|\n"); + + for (int i = 0; i < tablesize; i++) printf("+-----"); + printf("+\n"); +} + +int main(int argc, char * argv[]) { + int tab[10] = {}; + + srand(time(NULL)); + int rand_v = rand(); + + for (int i = 0; i < 10; i++) { + srand(rand_v); + tab[i] = rand() % 101 > 50 ? (-rand() % 100) + 50: (rand() % 100) - 50; + rand_v = rand(); + } + + showtable(10, tab); + + int reserversetab[10] = {}; + for (int i = 0; i < 10; i++) { + reserversetab[i] = tab[9-i]; + } + + printf("\n\n"); + showtable(10, reserversetab); + + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP11/recherche.c b/APL1.1/TP11/recherche.c new file mode 100644 index 0000000..9e5b28b --- /dev/null +++ b/APL1.1/TP11/recherche.c @@ -0,0 +1,53 @@ +#include +#include +#include + +#define TABSIZE 10 + +int main(int argc, char * argv[]) { + int tab[TABSIZE] = {}; + + srand(time(NULL)); + int rand_v = rand(); + + for (int i = 0; i < TABSIZE; i++) { + srand(rand_v); + tab[i] = rand() % 101 > 50 ? (-rand() % 100) + 50: (rand() % 100) - 50; + rand_v = rand(); + + printf("+-----"); + } + printf("+\n"); + + for (int i = 0; i < TABSIZE; i++) { + printf("| %3d ", tab[i]); + } + printf("|\n"); + + for (int i = 0; i < TABSIZE; i++) { + printf("+-----"); + } + printf("+\n"); + + int value; + int index = -1; + printf("Veuillez entrer une valeur : "); + scanf("%d", &value); + + for (int i = 0; i < TABSIZE; i++) { + if (tab[i] == value) { + index = i + 1; + break; + } + } + + if (index != -1) { + printf("L'index n°%d contient votre nombre.\n", index); + } else { + printf("Le tableau ne contient pas votre nombre.\n"); + } + + + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP11/remplissage.c b/APL1.1/TP11/remplissage.c new file mode 100644 index 0000000..cbf0db9 --- /dev/null +++ b/APL1.1/TP11/remplissage.c @@ -0,0 +1,31 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + int tab[10] = {}; + + srand(time(NULL)); + int rand_v = rand(); + + for (int i = 0; i < 10; i++) { + srand(rand_v); + tab[i] = rand() % 101 > 50 ? (-rand() % 100) + 50: (rand() % 100) - 50; + rand_v = rand(); + + printf("+-----"); + } + printf("+\n"); + + for (int i = 0; i < 10; i++) { + printf("| %3d ", tab[i]); + } + printf("|\n"); + + for (int i = 0; i < 10; i++) { + printf("+-----"); + } + printf("+\n"); + return EXIT_SUCCESS; +} +