#include #include #include #define TAM 8 int selectSort(int *vetor, int k) { int me, aux, i, troca; for(aux=0; aux < TAM-1; aux++) { me = aux; for (i=aux+1; i < TAM; i++) { if (vetor[i] < vetor[me]) { me = i; } } if (me != aux) { troca = vetor[aux]; vetor[aux] = vetor[me]; vetor[me] = troca; } if (aux==k) { printf("\n%d\n", vetor[aux]); } } return (0); } int main() { int pegaK, aux, vetor[TAM] = {7, 1, 3, 10, 17, 2, 21, 9}; //srand (time(NULL)); printf("\nK:\n"); scanf("%d", &pegaK); /*for (aux=0; aux < TAM; aux++) { vetor[aux] = (rand() % 89) + 10; printf("[%d] ", vetor[aux]); }*/ printf("\n\n"); for (aux=0; aux < TAM; aux++) { printf("[%d] ", vetor[aux]); } printf("\n\n"); selectSort(vetor, pegaK); return (0); }