Rabu, 10 Desember 2025

ex2105.c bubble short

/* ex1205.c */
#include <stdio.h>

int main()
{
    const int size=6;
    int bubble[]={95,60,6,87,50,24};
    int inner,outer,temp,x;

    /*display original array*/
    puts("Original Array:");
    for(x=0;x<size;x++)
        printf("%d\t",bubble[x]);
    putchar('\n');

    /*bubble short*/
    for(outer=0;outer<size-1;outer++)
    {
        for(inner=outer+1;inner<size;inner++)
        {
            if(bubble[outer]>bubble[inner])
            {
                temp=bubble[outer];
                bubble[outer]=bubble[inner];
                bubble[inner]=temp;
            }
        }
    }

    /*display sorted array*/
    puts("Sorted Array:");
    for(x=0;x<size;x++)
        printf("%d\t",bubble[x]);
    putchar('\n');
    return(0);
}
output:
Original Array:
95      60      6       87      50      24
Sorted Array:
6       24      50      60      87      95

Process returned 0 (0x0)   execution time : 0.100 s
Press any key to continue.

Tidak ada komentar:

Posting Komentar