Here is a simple c programme of bubble sorting:
#include<stdio.h>
int arr[10];
void bubblesort()
{
int i,j,temp;
int size=10;
for(i=0;i<10;i++)
{
for(j=i;j<size;j++)
{
if(arr[i]<arr[j+1])
{
temp=arr[i];
arr[i]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
void main()
{
int c;
clrscr();
for(c=0;c<10;c++)
{
printf("Enter any number: ");
scanf("%d",&arr[c]);
}
bubblesort();
for(c=0;c<10;c++)
printf("\n%d",arr[c]);
getch();
}
No comments:
Post a Comment