Bubble Sort Program In C Using Array – If you are looking for a bubble sort program in C with array example, this C programming tutorial will help you to learn how to write a program for bubble sort in C. Just go through this C programming example to learn about bubble sort, we are sure that you will be able to write an C program for bubble sort using array.
Bubble Sort in C
Table of Contents
- What is Bubble Sort?
- Bubble Sort Example
- Bubble Sort in C with Array
- Bubble Sort Program in C – Source Code
- C Program for Bubble Sort – Output
- C Programming Tutorials
- C Programming Examples
What is Bubble Sort?
Bubble Sort is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.
Bubble Sort Example
This below image illustrates what is bubble sort.
C Programming Tutorials
- Stack Push Pop Program in C Using Arrays
- Factorial Program in C Using Pointers
- Factorial Program in C Using While Loop
- C Program For Factorial Using For Loop
- Factorial Program in C Using Recursion Function
- C Program For Palindrome String
- C Program For Palindrome Numbers
- C Program To Reverse a String with Using Function
- C Program To Reverse a String without Using Function
- C Program To Reverse a String Using Recursion
Bubble Sort in C with Array
Learn how to write a bubble sort in c using array. Writing a c program for bubble sort can be done using various techniques like array, pointers, recursion, function but here in this program, we show how to write a bubble sort program in c using array in a proper way.
Bubble Sort Program in C – Source Code
You can copy paste the below bubble sort program in c compiler to check how the source code work. Or write your own program on bubble sort using this below c program for bubble sort.
/* BUBBLE SORT PROGRAM IN C USING ARRAY - BUBBLESORT.C */ #include<stdio.h> //program execution starts from here. int main() { int a[50],n,i,j,temp; //Variable declaration printf("Enter the size of array: "); scanf("%d",&n); //Taking size of the array from user printf("Enter the array elements: "); for(i=0;i<n;++i) scanf("%d",&a[i]); //Taking array elements from user for(i=1;i<n;++i) for(j=0;j<(n-i);++j) if(a[j]>a[j+1]) //Bubble sort in c using array logic { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } printf("\nArray after sorting: "); for(i=0;i<n;++i) printf("%d ",a[i]); //Printing elements after bubble sort return 0; }
C Program for Bubble Sort – Output
After you compile and run the above bubble sort program in c using array, your C compiler asks you to enter array size and array elements for bubble sort. After you enter elements, the program will be executed and give output like below expected output using bubble sort functionality.
Output:
Enter the size of array: 5
Enter the array elements: 29541
Array after sorting: 12459
C PROGRAMMING EXAMPLES
- C Program To Reverse a String Using Pointers
- C Program To Swap Two Numbers Using Two Variables
- C Program To Swap Two Numbers Using Three Variables
- C Program For Prime Numbers – Check a Number is Prime or Not
- C Program To Reverse a String with Using Function
- C Program to Reverse a String without Using Function
- C Program to Reverse a Sting Using Recursion