Ordenamiento burbuja en c++
C++
#include <iostream>
using namespace std;
void OrdenarBurbuja(int arreglo[], int tamano) {
for(int i = 0; i < tamano - 1; i++){
for(int j = 0; j < tamano - i - 1; j++){
if(arreglo[j] < arreglo[j + 1]){
swap(arreglo[j], arreglo[j + 1]);
}
}
}
}
int main(){
int tamanoArreglo;
cout << "Ingresa la cantidad de números (máximo 10): ";
cin >> tamanoArreglo;
if (tamanoArreglo <= 10){
int numeros[tamanoArreglo];
for (int i = 0; i < tamanoArreglo; i++){
cout << "Ingresa el número " << i + 1 << ": ";
cin >> numeros[i];
}
OrdenarBurbuja(numeros, tamanoArreglo);
cout << "Números ordenados de mayor a menor:" << endl;
for(int i = 0; i < tamanoArreglo; i++){
cout << numeros[i] << " ";
}
cout << endl;
} else{
cout << "La cantidad ingresada es mayor a 10. Inténtalo de nuevo." << endl;
}
return 0;
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.