C Program to Implement Bubble Sorting Using Two Dimension Array:C program for bubble sort is use to arrange the array element in either ascending or descending order according to user requirements. it is a simplex method to sort the array element. it is use the n-1 time looping to sort the element.
ALGORITHM:-
step 1 : start
step 2 : Enter length of array
step 3 : Enter element of array
step 4 : Compare first and second element and swap
step 5 : compare second and third element and swap
step 6 : repeat the process until all elements are sorted
step 7 : display the sorted array list
step 8 : Stop execution
PROGRAM CODE:-
#include<stdio.h>
#include<conio.h>
int main( )
{
int a[100];
int i, j, temp, n ;
printf("Enter the lenght of the array : \n");
scanf("%d",&n);
printf("Enter Element in array: \n");
for(j=0; j<n; j++)
{
scanf("%d",&a[j]);
}
//Sorting array using bubble sorting
for(j=0; j<n; j++)
{
for(i=j+1; i<n; i++)
{
if(a[j]>a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
//display array after sorted
printf ( "\n\nArray after sorting:\n") ;
for(j=0; j<n; j++)
{
printf("%d\t",a[j]);
}
getch();
}
OUTPUT:-
Enter the length of the array: 5
Enter element of the array:
5
1
9
5
4
Array after sorting:
1 4 5 5 9
C Program To Sort the array using bubble sorting How sort the array element your bubble sorting in ascending order bubble sorting using c
ConversionConversion EmoticonEmoticon