 # Bubble Sort Program In C Using Function

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

### 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.

## 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,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

### 1 thought on “Bubble Sort Program In C Using Function”

1. Decent website with easy explanation