Vision and dreams are the blueprints of soul and achievements.
-Mohammed Ahmed F

Bubble sort

#include<stdio.h>
#include<conio.h>
void bsort(int *p,int n)
{
int i,j,t;
for(i=0;i<n-1;i++)
{
for(j=0;j<(n-1)-i;j++)
{
if(p[j]>p[j+1])
{
t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
}
}
}
void main()
{
int a[100],n,i;
clrscr();
printf("\n Enter How many elements\n");
scanf("%d",&n);
printf("\nEnter %d Nos. \n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
bsort(a,n);
printf("\nArray After Sorting :\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
getch();
}

Output:

Enter How many elements
5
Enter 5 Nos.
30
50
20
90
70
Array After Sorting :
20 30 50 70 90

Share this

Related Posts

Dear User,

Thank you for your comment. Hope you like this blog. Kindly share us on Social Media so others can be updated.

-Chief Administrative Officer.