/* Read n value into array and sort them into ASCENDING ORDER (BUBBLE SORT METHOD) */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,j,n,t;
clrscr();
printf(“enter how many value in array\n”);
scanf(“%d”,&n);
printf(“Enter %d value \n”,n);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(“Original List :\n”);
for(i=0;i<n;i++)
printf(“%5d”,a[i]);
/* bubble sort logic */
for(i=1;i<n;i++)
for(j=0;j<n-i;j++)
if(a[j]>=a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
printf(“\n\nSorted list :\n”);
for(i=0;i<n;i++)
printf(“%5d”,a[i]);
getch();
}
Latest posts by Mohit Arora (see all)
- MongoDB Operators Tutorial – What are Different Operators Available? - October 5, 2019
- MongoDB Projection Tutorial : Return Specific Fields From Query - March 9, 2019
- MongoDB Index Tutorial – Create Index & MongoDB Index Types - July 6, 2018