bubble sort.
My dear friends , today we will discuss a program on sorting.
How we can sort a list in ascending or an descending order
with the help of C program.
Here is the program
#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
int i,j,temp,n,array[100];
printf(“\n how much and enter the elements for
array”);
scanf(“%d”,&n)
for(i=0;i<n;i++);
scanf(“%d”,&array[i]);
for(i=0;i<n;i++)
{ for(j=0;j=n-i-1;j++)
{ if(array[j]>array[j+1])
{ temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
Printf(“\n array in sorted order is”);
for(i=0;i<n;i++)
printf(“%d”,array[i]);
getch();
}
Comments
Post a Comment