diff --git a/Algorithmique/Exemples/comprendre.c b/Algorithmique/Exemples/comprendre.c new file mode 100644 index 0000000000000000000000000000000000000000..49916b138f5f0f7c91caad77c683cccbdd1b8cb6 --- /dev/null +++ b/Algorithmique/Exemples/comprendre.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define SIZE 10 + +int main() { + srand(time(NULL)); + double tab[SIZE]; + for (int i = 0; i < SIZE; ++i) { + tab[i] = rand() / (double)RAND_MAX; + } + + for (int i = 0; i < SIZE - 1; ++i) { + double min = tab[i]; + int ind_min = i; + for (int j = i + 1; j < SIZE; ++j) { + if (min > tab[j]) { + ind_min = j; + min = tab[j]; + } + } + double tmp = tab[i]; + tab[i] = tab[ind_min]; + tab[ind_min] = tmp; + } + + for (int i = 0; i < SIZE; ++i) { + printf("%f ", tab[i]); + } + printf("\n"); + + for (int i = 0; i < SIZE - 1; ++i) { + if (tab[i] > tab[i + 1]) { + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +}