Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void ordenacionSeleccion(int matriculas[20],char nombres[20][30],int validos);
- int main()
- {
- int matriculas[20];
- int edades[20];
- char nombres[20][30];
- int validos = cargarDatos(matriculas,nombres);
- mostrar(matriculas,nombres,validos);
- ordenacionSeleccion(matriculas,nombres,validos);
- mostrar(matriculas,nombres,validos);
- return 0;
- }
- int cargarDatos(int matriculas[20],char nombres[20][30])
- {
- int validos = 0;
- char mander = 's';
- while ((mander == 's') && (validos<20))
- {
- printf("ingrese matricula del alumno %d\n",validos+1);
- fflush(stdin);
- scanf("%d",&matriculas[validos]);
- printf("ingrese nombre del alumno %d\n",validos+1);
- fflush(stdin);
- scanf("%s",&nombres[validos]);
- printf("desea seguir? s/n \n");
- fflush(stdin);
- scanf("%c",&mander);
- validos++;
- }
- return validos;
- }
- void mostrar(int matriculas[20],char nombres[20][30], int validos)
- {
- int i = 0;
- for (i=0;i<validos;i++)
- {
- printf("Nombre --> %s\n",nombres[i]);
- printf("Mat --> %d\n",matriculas[i]);
- }
- }
- int posicionMenor(int arreglo[10],int validos, int pos)
- {
- int menor = arreglo[pos];
- int posMenor = pos;
- int indice = pos + 1;
- while (indice < validos)
- {
- if (menor > arreglo[indice])
- {
- menor = arreglo[indice];
- posMenor = indice;
- }
- indice++;
- }
- return posMenor;
- }
- void ordenacionSeleccion(int arreglo[],char nombres[20][30],int validos)
- {
- int indice = 0;
- int posMenor;
- int aux;
- char auxNombre[30];
- while (indice<validos-1)
- {
- //el menor de todos pero a partir de indice
- posMenor = posicionMenor(arreglo,validos,indice);
- aux = arreglo[posMenor];
- arreglo[posMenor] = arreglo[indice];
- arreglo[indice] = aux;
- strcpy(auxNombre,nombres[posMenor]);//destino - origen
- strcpy(nombres[posMenor],nombres[indice]);
- strcpy(nombres[indice],auxNombre);
- indice++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment