c program for bubble sort using functions

#include<stdio.h>
void bubble_sort(int a[],int num);
void display(int a[],int num);
int main()
{
int a[100],num,i;
printf("\nEnter the size of array\n");
scanf("%d",&num);
printf("\nEnter the elements one by one in array\n");
for(i=0;i<num;i++)
scanf("%d",&a[i]);
bubble_sort(a,num);
display(a,num);
return 0;
}
void bubble_sort(int a[],int num)
{
int i,temp,j;
printf("\nUnsorted data:");
for(i=0;i<num;i++)
printf("%d\n",a[i]);

{
for(i=0;i<num;i++)
{
for(j=0;j<num-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}}
void display(int a[],int num)
{
int i;
printf("sorted elements are:");

for(i=0;i<num;i++)

printf("%d\t",a[i]);
}

Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation