65 lines
1.1 KiB
C
65 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
void afficheTab(float tab[],int taille){
|
||
|
if(taille==0){
|
||
|
return;
|
||
|
} afficheTab(tab, taille-1);
|
||
|
printf("%.2f ",tab[taille-1]);
|
||
|
}
|
||
|
|
||
|
int indicePlusPetit(float tab[10]){
|
||
|
int taille=10;
|
||
|
int i;
|
||
|
int indice=0;
|
||
|
int min=tab[0];
|
||
|
|
||
|
for(i=1;i<taille;i++){
|
||
|
if (tab[i]<min){
|
||
|
min=tab[i];
|
||
|
indice=i;
|
||
|
}
|
||
|
} return indice;
|
||
|
}
|
||
|
|
||
|
int indicePlusPetitApresI(float tab[10],int indice){
|
||
|
int taille=10;
|
||
|
int i;
|
||
|
int indice2=indice;
|
||
|
int min=tab[indice];
|
||
|
|
||
|
for(i=indice;i<taille;i++){
|
||
|
if (tab[i]<min){
|
||
|
min=tab[i];
|
||
|
indice2=i;
|
||
|
}
|
||
|
} return indice2;
|
||
|
}
|
||
|
|
||
|
void echange2cases(float tab[10],int indice1,int indice2){
|
||
|
float temp;
|
||
|
temp=tab[indice1];
|
||
|
tab[indice1]=tab[indice2];
|
||
|
tab[indice2]=temp;
|
||
|
}
|
||
|
|
||
|
void triParSelection(float tab[10]){
|
||
|
int taille=10;
|
||
|
int i;
|
||
|
echange2cases(tab,indicePlusPetit(tab),0);
|
||
|
for (i=1;i<taille;i++){
|
||
|
echange2cases(tab,indicePlusPetitApresI(tab,i),i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(int argc, char const *argv[])
|
||
|
{
|
||
|
float tab[10]={43.8,17.0,212.12,251.7,891.18,78.0,182.0,526.19,98.1,290.0};
|
||
|
|
||
|
afficheTab(tab,10);
|
||
|
putchar('\n');
|
||
|
triParSelection(tab);
|
||
|
afficheTab(tab,10);
|
||
|
putchar('\n');
|
||
|
return 0;
|
||
|
}
|