C Program to sort elements using BUBBLE SORT

C Program for bubble sort: C programming code for bubble sort to sort numbers or arrange them in ascending order.

 

#include <stdio.h>
#include <conio.h>

int main()
{
int arr[10],i,n,temp,j;
printf(“Enter the size of array : “);
scanf(“%d”,&n);

printf(“nEnter the elements : n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&arr[i]);
}

printf(“nOriginal Array : n”);
for(i=0;i<n;i++)
{
printf(“%dt”,arr[i]);
}

for(i=0;i<n-1;i++)

{
for(j=0;j<(n-i)-1;j++)

{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}

}
}

printf(“nnSorted Array: n”);

for(i=0;i<n;i++)
{
printf(“%dt”,arr[i]);
}
getch();
}

 

OUTPUT

Advertisements