Advertisement
gonzalob

Untitled

Apr 25th, 2022
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int busquedaMenorElemento(int arreglo[5],int validos, int pos);
  5. int busquedaPosMenorElemento(int arreglo[5],int validos, int pos);
  6. void ordenacionSeleccion(int arreglo[5], int validos);
  7.  
  8. int main()
  9. {
  10.    int notas[5] = {20,15,10,9,1} ; //la primera va con 90 el resto en 0
  11.    int menor = busquedaMenorElemento(notas,5,0);
  12.    int posMenor = busquedaPosMenorElemento(notas,5,0);
  13.  
  14.    printf("el menor es %d\n",menor);
  15.    printf("la posMenor es %d\n",posMenor);
  16.  
  17.    ///?????
  18.    ordenacionSeleccion(notas,5);
  19.  
  20.    for (int indice = 0;indice<5;indice++)
  21.    {
  22.        printf("%d\n",notas[indice]);
  23.    }
  24.  
  25.     return 0;
  26. }
  27.  
  28.  
  29. int busquedaMenorElemento(int arreglo[5],int validos, int pos)
  30. {
  31.     //20
  32.     int menor = arreglo[pos]; //asumo que donde arranco es el menor
  33.     //1
  34.     int indice = pos+1;
  35.     while (indice < validos)
  36.     {
  37.         //20 > 5 // 5 > 10 // 5 > 9 // 5 > 1
  38.         if ( menor > arreglo[indice])
  39.         {
  40.             //5 -- 1
  41.             menor = arreglo[indice];
  42.         }
  43.         indice++;
  44.     }
  45.     return menor;//1
  46. }
  47.  
  48. ///fn para buscar la POS del menor elemento en un arreglo a partir de una posicion determinada
  49. int busquedaPosMenorElemento(int arreglo[5],int validos, int pos)
  50. {
  51.     int posMenor = pos; //donde arranco el arreglo
  52.     //20
  53.     int menor = arreglo[posMenor]; //asumo que donde arranco es el menor
  54.     //1
  55.     int indice = pos+1; //para ahorrar un ciclo
  56.     while (indice < validos)
  57.     {
  58.         //20 > 5 // 5 > 10 // 5 > 9 // 5 > 1
  59.         if ( menor > arreglo[indice])
  60.         {
  61.             //5 -- 1
  62.             menor = arreglo[indice];
  63.             posMenor = indice;
  64.         }
  65.         indice++;
  66.     }
  67.     return posMenor;//4 (los pos)
  68. }
  69.  
  70. ///fn para ordenar el arreglo
  71. void ordenacionSeleccion(int arreglo[5], int validos)
  72. {
  73.     int posMenor;
  74.     int aux;
  75.     int indice = 0;
  76.     while (indice < validos)
  77.     {
  78.         posMenor = busquedaPosMenorElemento(arreglo,validos,indice);
  79.         aux = arreglo[indice];
  80.         arreglo[indice] = arreglo[posMenor];
  81.         arreglo[posMenor] = aux;
  82.  
  83.         indice++;
  84.     }
  85.  
  86. }
  87.  
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement