Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Bubble Sort in C Programming Program | DSA Tutorials

YASH PAL, 7 May 20267 May 2026

Bubble sorting is one of the easiest to understand and program in C Programming. It is probably the least efficient. The basic idea underlying the bubble sort is to pass through the file sequentially several times. Each pass consists of comparing each element in the file with its successor and interchanging the two elements if they are not in proper order.

If you want a working example of bubble sorting and the steps of the algorithm how the bubble sort algorithm works, then read this tutorial – Bubble sorting algorithm example.

Bubble Sorting program in C Programming.

#include<stdio.h>
#include<conio.h>
#define SIZE 10

void bubble_sort(int [], int);

void main()
{
    int a[SIZE],n,i;
    printf("Enter how many elements ");
    scanf("%d",&n);
    /*Input array*/
    for(i=0;i<n;i++)
    {
        printf("Enter element %d ",i+1);
        scanf("%d",&a[i]);
    }
    bubble_sort(a,n);
    /*Output Array*/
    for(i=0;i<n;i++)
        printf("%d ",a[i]);
    getch();
}

void bubble_sort(int a[], int n)
{
    int i,j,swap,t;
    swap=1;
    i=1;
    
    while(i<n && swap == 1)
    {
        swap = 0;
        for(j=0;j<n-1;j++)
        {
            if(a[j]>a[j+1])
            {
                t = a[j];
                a[j] = a[j+1];
                a[j+1] = t;
                swap = 1;
            }
        }
        i++;
    }
}

Output

Enter how many elements 5
Enter element 1 10
Enter element 2 20
Enter element 3 1
Enter element 4 2
Enter element 5 3
1 2 3 10 20 
Data Structures Tutorials DSA Tutorials

Post navigation

Previous post
Next post

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes