#include <stdio.h>
#include <time.h>

#define MIN 12
#define MAX 18

void burbuja(int arreglo[], int n) {
    int i, j, aux;

    for (i = n - 1; i > 0; i--) {
        for (j = 0; j < i; j++) {
            if (arreglo[j] > arreglo[j + 1]) {
                aux = arreglo[j];
                arreglo[j] = arreglo[j + 1];
                arreglo[j + 1] = aux;
            }
        }
    }
}

int main() {

    int numeros[MAX];
    int cantidad, i;

    // Obtener fecha y hora actual
    time_t t = time(NULL);
    struct tm tm = *localtime(&t);

    printf("=================================\n");
    printf("Programa: Metodo Burbuja\n");
    printf("Jose Arturo Tafolla Aguayo\n");
    printf("Codigo: 224791815\n");
    printf("Fecha y hora: %s", asctime(&tm));
    printf("=================================\n\n");

    printf("Cuantos numeros va a ingresar? (12 a 18): ");
    scanf("%d", &cantidad);

    if (cantidad < MIN || cantidad > MAX) {
        printf("Cantidad no valida\n");
        return 0;
    }

    for (i = 0; i < cantidad; i++) {
        printf("Numero %d: ", i + 1);
        scanf("%d", &numeros[i]);
    }

    printf("\nNumeros originales:\n");
    for (i = 0; i < cantidad; i++) {
        printf("%d ", numeros[i]);
    }

    burbuja(numeros, cantidad);

    printf("\n\nNumeros ordenados:\n");
    for (i = 0; i < cantidad; i++) {
        printf("%d ", numeros[i]);
    }

    printf("\n");

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: