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
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 10
void find_min(double tab[], int i0, int *ind) {
double min = tab[i0];
*ind = i0;
void find_min(double tab[], int i0, int *ind, double *min) {
*min = tab[i0];
*ind = i0;
for (int i = i0 + 1; i < SIZE; ++i) {
if (min > tab[i]) {
if (*min > tab[i]) {
*ind = i;
min = tab[i];
*min = tab[i];
}
}
}
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
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