Skip to content
Programmingoneonone - Logo
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Computer System Architecture
    • Microprocessor
    • 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 - Logo
Programmingoneonone

Bubble Sort in C Program | DSA Tutorials

YASH PAL, 7 May 20268 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.

The method is called the bubble sort because each number slowly “bubbles” up to its proper position. In this sort, the number of interchanges cannot be greater than the number of comparisons. It is likely that it is the number of interchanges rather than the number of comparisons that takes up the most time in the program’s execution. The only redeeming features of the bubble sort are that it requires little additional space (one additional record to hold the temporary value for interchanging and several simple integer variables) and that it is O(N) in the case that the file is completely sorted (or most completely sorted).

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 & Algorithms Tutorials for Beginners
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
  • DMCA

Practice

  • Java
  • C++
  • C

Follow US

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