Sunday, October 16, 2011

Bubble Sort

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[100];
    int i=0,j=0,n,small,temp,pos;
    printf("Enter size of the array:");
    scanf(%d",&n);
    for(i = 0; i < n; i++)
    scanf("%d ", arr[i]);
    for(i =0; i <=n-1; i++)
    {
        for(j =0; j <=n-1; j++)
        if(a[j]>a[j+1])
        {
             temp=a[pos];
             a[pos] = a[i];
             a[i]=temp;
        }  
      
    }
    printf("Sorted Array is:\n");
    for(i = 0; i <n; i++)
    printf("%d\n", a[i]);
    getch();
}

No comments:

Post a Comment