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 arrayn”);
scanf(“%d”,&num);
printf(“nEnter the elements one by one in arrayn”);
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(“%dn”,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(“%dt”,a[i]);
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io

 

You have Successfully Subscribed!

Open chat