Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define NUM_ARREGLOS 10
- void verarreglo(int *ver){
- for(int i = 0; i != NUM_ARREGLOS; i++){
- printf("N%d) %d\n",i+1,ver[i]);
- }
- }
- void ordenarburbuja(int *arreglos, int na){ // Ana ES = A NUM_ARREGLOS
- //ALGORITMO BURBUJA
- int temp;
- for(int z = 1; z < na; ++z) {
- for(int v = 0; v < (na - z); v++) {
- if(arreglos[v] > arreglos[v+1]){
- temp = arreglos[v];
- arreglos[v] = arreglos[v + 1];
- arreglos[v + 1] = temp;
- }
- }
- }
- }
- int main(int argc, char **argv){
- int arreglo[NUM_ARREGLOS];
- for(int i = 0; i != NUM_ARREGLOS; i++){ // Creamos a I y pedimos que se repita el ciclo hasta que I (Ingresados) Sea igual a la cantidad de arreglos definida.
- printf("Ingrese el arreglo %d: ", i+1);
- scanf(" %d",&arreglo[i]); // Pedimos el arreglo y lo ingresamos en la posicion I..
- for(int z = 0; z != i; z++){ // Creamos a Z Y pedimos que se repita el for hasta que Z sea igual a I (Ingresados)
- if(arreglo[i] == arreglo[z]){ // COMPROBAMOS QUE EL ARREGLO INGRESADO (i) NO SEA IGUAL A NINGUNO DE LOS YA DEFINIDOS. (Z)
- printf("No se pueden repetir\n");
- i--; // Restamos uno a i para volver un ciclo antras en el for.
- break; //Salir del ciclo for
- }
- }
- }
- printf("Orden ingresado:\n");
- verarreglo(arreglo);
- printf("Orden burbuja:\n");
- ordenarburbuja(arreglo, NUM_ARREGLOS);
- verarreglo(arreglo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement