Simple C Programs Using Sorting & Searching : Bubble Sort - String C Program

If you are sorting the data in Increasing/Ascending order, using Bubble sorting method, first A(1) and A(2) are compared, if A(1) is bigger than A(2) then both the numbers are interchanged. Otherwise next A(2) and A(3) are compared.
This comparing and interchanging will go on until all the elements are compared and interchanged.
/* Bubble sort using function */
#include <stdio.h>
void bubble (int n, int x[ ]);
void main()
{
int i,n,a[10]; /* Local definitions */
/* Statements */
printf("Enter upper limit \n");
scanf("%d", &n);
for(i=0; i<n; i++)
scanf("%d", & a[i]);
bubble (n,a);
printf ("After sorting");
for (i=0; i<n;i++)
printf ("%d\t", a[i]);
} /* main */
void bubble (int n, int x[])
{
int i, item, temp;
for (item = 0; item <n‒1; ++item)
{
for (i =item +1; i< n; ++i)
{
if(x[i] < x[item])
{
temp = x[item];
x[item]=x[i];
x[i] = temp;
} /* if */
} /* for */
} /* for */
return;
} /* bubble */
OUTPUT
Enter upperlimit : 5
1 5 3 4 2
After Sorting 1 2 3 4 5
EXPLANATION: Program reads n elements to the array and sort the array of elements using bubbles sort method.
Computer Programming C Laboratory: String C Programs : Tag: C Programming : - C Program to Bubble sort using function
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation