Monday, August 5, 2013

Bubble Sort C Language

#include/*stdio.h*/
void swap(int *a,int *b);
main()
{
int ar[5],i,j,n;
ar[0]=7;ar[1]=3;ar[2]=9;ar[3]=2;ar[4]=11;
printf("Array before sort:\n\n");
for(i=0;i<5;i++)
printf("ar[%d]=%d\n",i,ar[i]);
n=5; /*numberof items in sort array*/
for(i=0;i for(j=0;j {
if(ar[j]>ar[j+1])
swap(&ar[j],&ar[j+1]);
}
printf("Array after sort:\n\n");
for(i=0;i<5;i++)
printf("ar[%d]=%d\n",i,ar[i]);
system("pause");
return 0;
}
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}

To Know What Is Game Programming in C Language., Click Me@Free

 

No comments:

Post a Comment