Bubble sort
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
void main()
{
int n,i,j,temp;
printf("enter the size of array: ");
scanf("%d",&n);
int a[n];
printf("Enter the elements of array:\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
for(j=0;j<n-1-i;j++)
{
if(a[j+1]<a[j])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
printf("\ Sorted elements of array:\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
Comments
Post a Comment