diff --git a/header/tab_uni_malloc.h b/header/tab_uni_malloc.h index 0814bfdfb27f9047e300f4e7f3cb978f314a4b8c..3141c930d0ffbc9860b50004420a23f7c228abd6 100644 --- a/header/tab_uni_malloc.h +++ b/header/tab_uni_malloc.h @@ -80,4 +80,15 @@ int64_t FindLowIndex(int64_t *tab, int64_t tab_len); */ void TriInsertionDescent(int64_t *tab, int64_t tab_len); +/** + @brief Find how many smaller value than val in table + @param [int] *tab, input table + @param [int] tab_len, table lenght + @param [int] val + @return [int64_t] How many value +*/ +int64_t FindHowManySmaller(int64_t *tab, int64_t tab_len, int64_t val); + + + #endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index 29d458dd532fd9ebf23e4ef0960e4869e7cfa586..6e6529baf819bf4bc1669342c3bb420e9057616b 100644 --- a/src/main.c +++ b/src/main.c @@ -47,7 +47,14 @@ int main() PrintTableau(tab, size); //8. + int64_t input_value = 0; + printf("\nEntrez une valeur : \n"); + scanf(" %ld", &input_value); + printf("Il y a %ld d'élements plus petit que %ld dans le tableau. \n", FindHowManySmaller(tab,size, input_value),input_value); + + //9. + //Free the Malloc free(tab); return 0; diff --git a/src/tab_uni_malloc.c b/src/tab_uni_malloc.c index 65272430029cbde7ddb613d7daa69399e899bebe..8607f46a33c3ce16f4ae3858300bc0f1e7024a99 100644 --- a/src/tab_uni_malloc.c +++ b/src/tab_uni_malloc.c @@ -147,3 +147,20 @@ void TriInsertionDescent(int64_t *tab, int64_t tab_len) tab[pos] = tmp; } } + +/** + @brief Find how many smaller value than val in table + @param [int] *tab, input table + @param [int] tab_len, table lenght + @param [int] val + @return [int64_t] How many value +*/ +int64_t FindHowManySmaller(int64_t *tab, int64_t tab_len, int64_t val) +{ + int64_t compteur = 0; + for (int64_t i = 0; i < tab_len; i++) + { + if(tab[i] < val){compteur++;} + } + return compteur; +}