Bubble shorting in c programming
BM Balmiki Mandal 20 Sep 2022 6 views 0 comments C Programming

Bubble shorting in c programming

Bubble Sorting in C Programming - Algorithm and Example

Bubble sorting is a simple sorting algorithm that works by repeatedly comparing adjacent elements in a list and swapping them if they are in the wrong order. The algorithm is named after the way that the larger elements "bubble up" to the top of the list.

Bubble sorting is a stable sorting algorithm, which means that it preserves the order of equal elements in the list. It is also an in-place sorting algorithm, which means that it does not require any additional memory.

C program to Bubble shorting 

#include<stdio.h>
void main()
{
    int a[5],i,j,t,ele;
    ele=sizeof(a)/sizeof(a[0]);
    printf("Enter the array elements:");
    for(i=0;i<ele;i++)
    scanf("%d",&a[i]);
    printf("Unshorted Elements:");
    for(i=0;i<ele;i++)
    printf(" %d",a[i]);
    printf("\n");
    for(i=0;i<ele;i++)
    {
        for(j=0;j<ele-1-i;j++)
        {
            if(a[j]>a[j+1])
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    }
    printf("shorted Elements:");
    for(i=0;i<ele;i++)
    printf(" %d",a[i]);
    printf("\n");
}

Output:

Enter the array elements: 5 15 1 25 12
Unsorted Elements:  5 15 1 25 12
shorted Elements:  1 5 12 15 25

Further Reading:

Bubble shorting in c programming

Bubble short in string in c

Write a c program to short 2D array using bubble short

Selection shorting in c Programming

Enroll Now:

[ C-Programming From Scratch to Advanced 2023-2024] "Start Supercharging Your Productivity!"

Contact Us:

  • For any inquiries, please email us at [info@electro4u.net].
  • Follow us on insta  [ electro4u_offical_ ] for updates and tips.

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026
Topic-wise C Programming Interview Questions

C Programming Interview Questions – Topic Wise1. IntroductionC programming is one of the most important langu...

AG Anvesh G 30 May 2026