Bubble Sort Program In C Using Function. If you are looking for a bubble sort program in C with function 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 tutorial to learn about bubble sort, we are sure that you will be able to write a C program for bubble sort using function.
Bubble Sort in C
Table of Contents
- What is Bubble Sort?
- Bubble Sort Example
- Bubble Sort in C with Function
- Bubble Sort Program in C Using Function – Source Code
- C Program for Bubble Sort Using Function – 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 in C.
C Programming Tutorials
- Bubble Sort Program in C Using Array
- 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
Bubble Sort in C with Function
Learn how to write a bubble sort in c using function. Writing a Bubble Sort C Program can be done using various techniques like an array, pointers, recursion, function but here in this program, we show how to write a bubble sort program in c using function in a proper way.
Bubble Sort Program in C Using Function – 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 Bubble Sort in C Using Function with the help of this below c program for bubble sort.
/* BUBBLE SORT PROGRAM IN C USING FUNCTION - BUBBLESORT.C */
#include<stdio.h>
#include<stdlib.h>
void bubblesort(int a[],int size);
void main()
{
int a[50],n,i;
printf("\n Enter the size of the array");
scanf("%d",&n);
if(n>50)
{
printf("\n error");
exit(0);
}
printf("\n Enter the array elements: \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
bubblesort(a,n);
printf("\n The sorted array is\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
}
void bubblesort(int a[],int size)
{
int temp,i,j;
for(i=0;i<size;i++)
{
for(j=0;j<size-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
C PROGRAM FOR BUBBLE SORT – OUTPUT
After you compile and run the above bubble sort program in c using function, your C compiler asks you to enter 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 the array: 5
Enter the array elements: 29541
The sorted array is 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
- 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
Decent website with easy explanation