diff --git a/APL1.1/TP15/decoupage.c b/APL1.1/TP15/decoupage.c new file mode 100644 index 0000000..721fd72 --- /dev/null +++ b/APL1.1/TP15/decoupage.c @@ -0,0 +1,40 @@ +#include +#include + +#define SIZE 10 + +void drawTriangle() { + for (int i = 0; i <= SIZE; i++) { + for (int i2 = SIZE-i; i2 > 0; i2--) printf(" "); + for (int i2 = 0; i2 < i*2-1; i2++) printf("* "); + printf("\n"); + } +} + +void drawSquare() { + for (int x = 0; x < SIZE; x++) { + for (int y = 0; y < SIZE; y++) { + printf("* "); + } + printf("\n"); + } +} + +int showMenu() { + int choice; + puts("Que voulez vous dessiner ?"); + puts("1. Carré"); + puts("2. Triangle"); + scanf("%d", &choice); + + return choice; +} + +int main(int argc, char * argv[]) { + int choice = showMenu(); + + if(choice == 1) drawSquare(); + else drawTriangle(); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP15/echange.c b/APL1.1/TP15/echange.c new file mode 100644 index 0000000..1615871 --- /dev/null +++ b/APL1.1/TP15/echange.c @@ -0,0 +1,17 @@ +#include +#include + +void swap(int* x, int* y) { + int z = *x; + *x = *y; + *y = z; +} + +int main(int argc, char * argv[]) { + int x = 10, y = 3; + printf("x = %d; y = %d\n", x, y); + swap(&x, &y); + printf("x = %d; y = %d\n", x, y); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP15/miroir.c b/APL1.1/TP15/miroir.c new file mode 100644 index 0000000..81d418a --- /dev/null +++ b/APL1.1/TP15/miroir.c @@ -0,0 +1,54 @@ +#include +#include +#include + +#define SIZE 10 + +void filltable(int table[]) { + srand(time(NULL)); + for (int i = 0; i < SIZE; i++) { + table[i] = rand() % 100; + srand(rand()); + } +} + +void showtable(int table[]) { + for (int i = 0; i < SIZE; i++) printf("+----"); + printf("+\n"); + + for (int i = 0; i < SIZE; i++) printf("| %2d ", table[i]); + printf("|\n"); + + + for (int i = 0; i < SIZE; i++) printf("+----"); + printf("+\n"); +} + +/* Sans la fonction de l'exo 4 +void reversetable(int table[SIZE]) { + int normaltable[SIZE]; + for (int i = 0; i < SIZE; i++) normaltable[i] = table[i]; + for (int i = 0; i < SIZE; i++) table[i] = normaltable[SIZE-1-i]; +} */ + +//Avec la fonction de l'exo 4 +void swap(int* x, int* y) { + int z = *x; + *x = *y; + *y = z; +} + +void reversetable(int table[SIZE]) { + for (int i = 0; i < SIZE/2; i++) swap(&table[i], &table[SIZE-i-1]); +} + +int main(int argc, char * argv[]) { + int table[SIZE]; + + filltable(table); + showtable(table); + reversetable(table); + showtable(table); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP15/produit.c b/APL1.1/TP15/produit.c new file mode 100644 index 0000000..b56548c --- /dev/null +++ b/APL1.1/TP15/produit.c @@ -0,0 +1,23 @@ +#include +#include + +int main(int argc, char * argv[]) { + long val = 1; + int success = 0; + + for (int i = 1; i < argc; i++) { + char * pointer; + + long valeur = strtol(argv[i], &pointer, 10); + + if (!(pointer == argv[i])) { + val *= valeur; + success++; + } + } + + if (argc > 1 && success > 0) printf("Valeur : %ld\n", val); + else puts("Veuillez indiquer des entiers valides lors de l'exécution."); + return EXIT_SUCCESS; +} + diff --git a/APL1.1/TP15/zero.c b/APL1.1/TP15/zero.c new file mode 100644 index 0000000..53772a9 --- /dev/null +++ b/APL1.1/TP15/zero.c @@ -0,0 +1,15 @@ +#include +#include + +void zero(double* a) { + *a = 0.0; +} + +int main(int argc, char * argv[]) { + double x=37.5; + printf("avant : %f\n", x); + zero(&x); + printf("après : %f\n", x); + return EXIT_SUCCESS; +} +