//Bubble
Sorting Using C
#include<stdio.h>
#include<conio.h>
void
main()
{
//Declaration
of Variables
int arr[20],i,j,n,temp;
clrscr();
printf("How many elements you want to
sort?\n");
scanf("%d",&n);
//Entry
of Elements
printf("Enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]>arr[j])
{
//Swapping
of elements
temp=arr[i];arr[i]=arr[j];arr[j]=temp;
}
}
}
printf("After Sorting(increasing
order)the elements are\n");
for(i=0;i<n;i++)
{
printf("%d\t",arr[i]);
}
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.