Program :-
#include<stdio.h>
int A[100]; //global variable
void bblsrt(int n) //Entering the function to perform bubble sort
{
void main() //Entering main function
{
Output :-
Eg 1:-
Enter the array size : 5
Enter the array elements : 32 45 18 25 56
The sorted array is : 18 25 32 45 56
#include<stdio.h>
int A[100]; //global variable
void bblsrt(int n) //Entering the function to perform bubble sort
{
int i=0;char ch;}
int intrchng=0,pass=0;
while(pass<n-1 && intrchng==0) //Passing starts
{
i=0;intrchng=1;}
while(i<n-(pass+1))
{
if(A[i]>A[i+1]) //Swapping}
{
int t=A[i];}
A[i]=A[i+1];
A[i+1]=t;
intrchng=0;
i++; //Incrementing i
if(intrchng==1) //Return
return;
pass++; //Incrementing pass
void main() //Entering main function
{
int n,i;}
printf("Enter the array size : "); //Reading array size
scanf("%d",&n);
printf("Enter the array elements :"); //Reading array elements
for(i=0;i<n;++i)
scanf("%d",&A[i]);bblsrt(n); //Calling function to perform Bubble sort
printf("The sorted array is :"); //Printing sorted elements
for(i=0;i<n;++i)
printf("%d\t ",A[i]);
Output :-
Eg 1:-
Enter the array size : 5
Enter the array elements : 32 45 18 25 56
The sorted array is : 18 25 32 45 56
No comments:
Post a Comment