#Bubble sort descending

11 messages · Page 1 of 1 (latest)

muted parrot
#

Hey! How can I edit this ascending program to descending with bubble sort?

`#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"); 

}
`

slender matrixBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

sleek hearth
#

What have you tried so far

muted parrot
#

the numbers printed should go for 4,3,2,1 instead of 1,2,3,4. that's all i want.

#

haven't tried anything

sleek hearth
#

Well, play around with your code 😉

muted parrot
#

lol

sleek hearth
#

Programming is a creative problem solving process

#

It's really important to reason through your code and try things, and just messing around having fun trying things is honestly a great way to go

muted parrot
#

yeah, i just noticed my error was too simple

#

can you remember me how can i mark as solved this?