commit 8836358b0665334a9501ee735970e377b8e2e0ce Author: fauvet Date: Tue Dec 3 12:30:00 2024 +0100 Ajout du controle trop pas EZ diff --git a/4f347fe7-cb7b-4f68-96e0-39d096f89c52_Contrle_DV5.1_.pdf b/4f347fe7-cb7b-4f68-96e0-39d096f89c52_Contrle_DV5.1_.pdf new file mode 100644 index 0000000..8c19dcf Binary files /dev/null and b/4f347fe7-cb7b-4f68-96e0-39d096f89c52_Contrle_DV5.1_.pdf differ diff --git a/ex1/main.c b/ex1/main.c new file mode 100644 index 0000000..e57fa75 --- /dev/null +++ b/ex1/main.c @@ -0,0 +1,122 @@ +#include +#include +#include + +int racineCarree(int n){ + for(int i = 0; i < n; i++) { + if (i*i == n) { + return i; + } + } + return -1; +} + +int* RacineCarreeTab(int base_tab[], int tab_length) { + int* computedTab = (int*)malloc(tab_length * sizeof(int)); + + for (int i = 0; i < tab_length; i++) { + computedTab[i] = racineCarree(base_tab[i]); + } + + return computedTab; +} + +int* firstSort(int square_root_tab[], int tab_length, int tab_value) { + int* computedTab = (int*)malloc(tab_length * sizeof(int)); + + for (int i = 0; i < tab_length; i++) { + if(i%2 == 0) { + computedTab[i] = square_root_tab[i]; + } else { + computedTab[i] = square_root_tab[i] * tab_value; + } + } + + return computedTab; +} + +int* secondSort(int square_root_tab[], int tab_length) { + int* computedTab = (int*)malloc(tab_length * sizeof(int)); + + for (int i = 0; i < tab_length; i++) { + if(i%2 == 0) { + computedTab[i] = racineCarree(square_root_tab[i]); + } else { + int summ = 0; + int* result = RacineCarreeTab(square_root_tab, tab_length); + for(int j = 0; j= 0 ) { + printf("la racine carré de %d est = %d\n", base_number, foundSquareRoot); + } else { + printf("Aucune racine carrée trouvé pour : %d\n", base_number); + }*/ + + + + /* Exo 1 B*/ + + //int base_tab[5] = {1, 4, 9, 16, 25}; // VALEURS DU TABLEAU SI NON ALEATOIRE + //int tab_length = 5; + + int tab_length = atoi(argv[1]); //TAILLE DU TABLEAU + int base_tab[tab_length]; //VALEURS DU TABLEAU + srand(time(NULL)); + for(int j = 0; j < tab_length; j++) { + //MODIFIER ICI POUR DES PLUS PETITES VALEURS SI ALEATOIRE + base_tab[j] = rand(); + } + + int* result = RacineCarreeTab(base_tab, tab_length); + for (int i = 0; i < tab_length; i++) { + printf("%d\t", result[i]); + } + printf("\n"); + free(result); + + + /*Exo 3 + //int base_tab[5] = {1, 5, 9, 16, 25}; // VALEURS DU TABLEAU SI NON ALEATOIRE + //int tab_length = 5; + + int tab_length = atoi(argv[1]); //TAILLE DU TABLEAU + int base_tab[tab_length]; //VALEURS DU TABLEAU + srand(time(NULL)); + for(int j = 0; j < tab_length; j++) { + //MODIFIER ICI POUR DES PLUS PETITES VALEURS SI ALEATOIRE + base_tab[j] = rand(); + } + + int* sorted_tab = TriSpecial(RacineCarreeTab(base_tab, tab_length), tab_length); + printf("\n"); +*/ +} diff --git a/ex1/main_opti.c b/ex1/main_opti.c new file mode 100644 index 0000000..b8c6e09 --- /dev/null +++ b/ex1/main_opti.c @@ -0,0 +1,125 @@ +#include +#include +#include + +int racineCarree(int n){ + for(int i = 0; i < n; i++) { + if (i * i > n) { + break; + } + if (i*i == n) { + return i; + } + } + return -1; +} + +int* RacineCarreeTab(int base_tab[], int tab_length) { + int* computedTab = (int*)malloc(tab_length * sizeof(int)); + + for (int i = 0; i < tab_length; i++) { + computedTab[i] = racineCarree(base_tab[i]); + } + + return computedTab; +} + +int* firstSort(int square_root_tab[], int tab_length, int tab_value) { + int* computedTab = (int*)malloc(tab_length * sizeof(int)); + + for (int i = 0; i < tab_length; i++) { + if(i%2 == 0) { + computedTab[i] = square_root_tab[i]; + } else { + computedTab[i] = square_root_tab[i] * tab_value; + } + } + + return computedTab; +} + +int* secondSort(int square_root_tab[], int tab_length) { + int* computedTab = (int*)malloc(tab_length * sizeof(int)); + + for (int i = 0; i < tab_length; i++) { + if(i%2 == 0) { + computedTab[i] = racineCarree(square_root_tab[i]); + } else { + int summ = 0; + int* result = RacineCarreeTab(square_root_tab, tab_length); + for(int j = 0; j= 0 ) { + printf("la racine carré de %d est = %d\n", base_number, foundSquareRoot); + } else { + printf("Aucune racine carrée trouvé pour : %d\n", base_number); + }*/ + + + + /* Exo 1 B*/ + + //int base_tab[5] = {1, 4, 9, 16, 25}; // VALEURS DU TABLEAU SI NON ALEATOIRE + //int tab_length = 5; + + int tab_length = atoi(argv[1]); //TAILLE DU TABLEAU + int base_tab[tab_length]; //VALEURS DU TABLEAU + srand(time(NULL)); + for(int j = 0; j < tab_length; j++) { + //MODIFIER ICI POUR DES PLUS PETITES VALEURS SI ALEATOIRE + base_tab[j] = rand(); + } + + int* result = RacineCarreeTab(base_tab, tab_length); + for (int i = 0; i < tab_length; i++) { + printf("%d\t", result[i]); + } + printf("\n"); + free(result); + + + /*Exo 3 + //int base_tab[5] = {1, 5, 9, 16, 25}; // VALEURS DU TABLEAU SI NON ALEATOIRE + //int tab_length = 5; + + int tab_length = atoi(argv[1]); //TAILLE DU TABLEAU + int base_tab[tab_length]; //VALEURS DU TABLEAU + srand(time(NULL)); + for(int j = 0; j < tab_length; j++) { + //MODIFIER ICI POUR DES PLUS PETITES VALEURS SI ALEATOIRE + base_tab[j] = rand(); + } + + int* sorted_tab = TriSpecial(RacineCarreeTab(base_tab, tab_length), tab_length); + printf("\n"); +*/ +}