Program for Bubble Sort :->
#include<conio.h>
#include<stdio.h>
void main()
{
int ar[50],i,j,n,temp,pass;
clrscr();
printf("Enter Maximum number of elements u want to insert into the array");
scanf("%d",&n);
printf("\nplease enter the values of your array now:->");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
for(i=0;i<n;i++) //External loop for passes
{
for(j=0;j<n-i;j++) //Inner loop for traversing
{
if(ar[j]>ar[j+1])
{
temp=ar[j]; //code to swap the values of corresponding places.
ar[j]=ar[j+1];
ar[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("\n%d",ar[i]);
}
getch();
}
Enjoy your program..
No comments:
Post a Comment
Please write your Views about this Post here:->;