HOME

Tuesday, April 18, 2017

BUBBLE SORT - C PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],size,i,j,temp;
printf("Enter Size of Array\n");
scanf("%d",&size);
printf("Input %d value",size);
for(i=0;i<size;i++)
{
    scanf("%d",&a[i]);
}
for(i=size;i>1;i--)
{
    for(j=0;j<i-1;j++)
    {
        if(a[j]>a[j+1])
        {
            temp=a[j+1];
            a[j+1]=a[j];
            a[j]=temp;
        }
    }
}
printf("\nThe array element after sorting is\n");
for(i=0;i<size;i++)
{
    printf("%d\n",a[i]);
}
getch();
}

No comments:

Post a Comment