Bubble sort program in C using arrays and function. It is a type of sorting mechanism. Sample program also available for your reference. Source code of this C tutorial is given below,
[Read: Software Company List] & [Aptitude online portal]
BUBBLE SORT IN C
Bubble sort program in C is used to arrange the given values in an ascending order by using arrays and functions. And also an operation of this sorting will be based on some statements like unconditional statements. We can easily get the list of output values in an order. For example, your value is 3,7,1,10,9,-88. After bubble sorting, your input will display as -88,1,3,7,9,10.
BUBBLE SORT EXAMPLE PROGRAM:
Q: Write a C program for Bubble sort using arrays and function.
//Header files #include<stdio.h> #include<conio.h> void main() { //Program variables int b[20],j,i,m,h=0; clrscr(); //Function to clear previous output printf("Enter array size:"); //Display function scanf("%d",&m); //Getting input function printf("Enter %d elements:" ,n); for(i=1;i<=m;i++) //Looping statement scanf("%d",&b[i]); for(i=2;i<=m;i++) { j=i-1; while((j>=1)&&(b[j]>b[j+1])) //Unconditional statement { h=b[j]; b[j]=b[j+1]; b[j+1]=h; j=j-1; } } printf("Sorted List is::\n"); for(i=1;i<=n;i++) printf("%d\t",b[i]); getch(); }