//Bubble Sort.
#include<stdio.h>
#include<conio.h>
void main()
{
int ar[50],i,j,num,temp;
clrscr();
printf("Enter the number of elements of the Array:\t");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\nEnter element %d :",i+1);
scanf("%d",&ar[i]);
}
for(i=0;i<num;i++)
for (j=0;j<num-i-1;j++)
if(ar[j]>ar[j+1])
{
temp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=temp;
}
printf("\nThe Sorted array is:\n");
for(i=0;i<=num-1;i++)
printf("%d\t",ar[i]);
getch();
}
0 comments:
Post a Comment