Skip to content

Instantly share code, notes, and snippets.

@yesidays
Created July 16, 2012 10:01
Show Gist options
  • Save yesidays/3121889 to your computer and use it in GitHub Desktop.
Save yesidays/3121889 to your computer and use it in GitHub Desktop.
Método de burbuja
#include <stdio.h>
#define MAX 100
int main() {
int total;
int vNumeros[MAX];
int j, i, temp;
printf ("Cuantos numeros deseas ordenar? ");
scanf("%d", &total);
/* Lee y almacena los datos en el arreglo */
for (i = 0; i < total; i++) {
printf ("%d: ", i + 1);
scanf ("%d", &vNumeros[i]);
}
/* Método de búrbuja */
for (i = 0; i < (total - 1); i++) {
for (j = i + 1; j < total; j++) {
if (vNumeros[j] < vNumeros[i]) {
temp = vNumeros[j];
vNumeros[j] = vNumeros[i];
vNumeros[i] = temp;
}
}
}
/* Números ordenados */
printf ("Los números ordenados son:\n");
for (i = 0; i < total; i++) {
printf("%d | ", vNumeros[i]);
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment