Created
July 16, 2012 10:01
-
-
Save yesidays/3121889 to your computer and use it in GitHub Desktop.
Método de burbuja
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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