Home » C Programs » C Program to Implement Bubble Sort

C Program to Implement Bubble Sort

C Program to implement bubble sort. This program is executed in the concept using bubble sort in c. This program is executed in the concept using bubble sort in c. This working algorithm is a bit easier to execute and to understand the sorting program. Bubble sort is also one of the most important sorting methods in sorting algorithms. 

Sorting Definition in C

Sorting is the process of ordering or placing a collection’s parts in some sort of order. It simply refers to the storage of data in a sorted arrangement. It is possible to sort in both ascending and descending order. It organises the data in a logical order to facilitate searching. 

Temp Variable in C

A temporary variable is a variable in computer programming that has a brief lifetime and is used to retain data that will be removed quickly or before it can be stored in a more permanent memory location. It is commonly stated as a local variable, or a variable with local scope, because it is short-lived.

C Program to Implement Bubble Sort

//c program to implement bubble sort
#include<stdio.h>
int main()
{
int count, temp, i, j, num[30];
printf("Enter the numbers");
scanf("%d",&count);
printf("Enter %d nums: ",count);
for(i=0;i<count;i++)
scanf("%d",&num[i]);
for(i=count-2;i>=0;i--){
for(j=0;j<=i;j++){
if(num[j]>num[j+1]){
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
printf("Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",num[i]);
return 0;
}

Output 

Enter the numbers

3

Enter 3 num:

34 45 67

Sorted elements: 34 45 67