Skip to content
Snippets Groups Projects
Verified Commit bff60c0d authored by orestis.malaspin's avatar orestis.malaspin
Browse files

code is correct now

parent e50b8963
Branches
Tags
No related merge requests found
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#define SIZE 10 #define SIZE 10
void find_min(double tab[], int i0, int *ind) { void find_min(double tab[], int i0, int *ind, double *min) {
double min = tab[i0]; *min = tab[i0];
*ind = i0; *ind = i0;
for (int i = i0 + 1; i < SIZE; ++i) { for (int i = i0 + 1; i < SIZE; ++i) {
if (min > tab[i]) { if (*min > tab[i]) {
*ind = i; *ind = i;
min = tab[i]; *min = tab[i];
} }
} }
} }
int main() { int main() {
srand(time(NULL));
double tab[SIZE]; double tab[SIZE];
for (int i = 0; i < SIZE; ++i) { for (int i = 0; i < SIZE; ++i) {
tab[i] = rand() / (double)RAND_MAX; tab[i] = rand() / (double)RAND_MAX;
} }
for (int i = 0; i < SIZE - 1; ++i) { for (int i = 0; i < SIZE - 1; ++i) {
double double min = tab[i];
int ind_min = i;
find_min(tab, i, &ind_min, &min);
double tmp = tab[i];
tab[i] = min;
tab[ind_min] = tmp;
} }
for (int i = 0; i < SIZE; ++i) {
printf("%f ", tab[i]);
}
printf("\n");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment