Write a Program in c that implement Bubble sort, to sort a given list of integers in ascending order

/* Write a Program in c that implement Bubble sort, to sort a given list of integers in ascending   order*/

 

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{

int arr[10],i,j,n,temp;
printf("Enter array size:  ");
scanf("%d",&n);
printf("enter array elements for bubble sort :  ");
for(i=1;i<=n;i++)
{
scanf("%d",&arr[i]);
printf("\n ");
}
for(i=1;i<=n;i++)

{
for(j=1;j<=n;j++)

{
if(arr[j]>arr[j+1]){
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("array after applying bubble sort : ");

for(i=1;i<=n;i++){
printf("\n %d \n ",arr[i]);
}
getch();
}
 

Comments

Popular posts from this blog