Bubble Sort Program in C Using Function

bubble sort program in c using function. In this program, we can execute the bubble sort in c using a function for beginners.

Bubble Sort Definition in C

Binary search is a search approach in computer science that locates a target value within a sorted array. It’s also known as binary chop, half-interval search, or logarithmic search. 

The target value is compared to the array’s middle element in a binary search. Binary Search is a search algorithm for locating a specified element in a sorted array. 

Before executing a binary search, the array should be sorted. Logarithmic search, binary chop, and half interval search are all terms used to describe binary search.

Function Definition in C

A function is a group of statements that cooperate to accomplish a goal. Every C program has at least one function, main(), and even the most basic programmes can have more. 

A function declaration specifies the name, return type, and parameters of the function. A function is a logical unit of code whose location in a larger code structure is frequently stated. 

A function is a piece of code that takes a number of inputs, many of which are variables, and provides real outputs like changing variable values or doing actual operations based on the inputs.

Insertion Sort Program in C Using Array

#include<stdio.h>
#include<stdlib.h>
int function(int a[],int size);
int main()
{
int a[50],n,i;
printf("\n Enter The Size of Array");
scanf("%d",&n);
if(n>50)
{
printf("\n error");
exit(0);
}
printf("\n Enter The Array Elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
func(a,n);
printf("\n The Sorted Array is\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
}
void func(int a[],int size)
{
int temp,i,j;
for(i=0;i<size;i++)
{
for(j=0;j<size-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}

Output:

Enter The Size of Array 3

Enter The Array Elements
34
56
78

The Sorted Array is
34 56 78