Search Your Query

Breaking

Friday, June 7, 2019

Bubble Sorting


Bubble Sorting

Program Code :

#include<stdio.h>
#include<stdlib.h>
int main()
{
int *a,i,j,n,temp;
printf("Enter the size of array\n");
scanf("%d",&n);
a=(int*)malloc(n*sizeof(int));
printf("Enter the elements of array\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("The sorted array is -->%d\n",a[i]);
}
return 0;

}

Hence , Coming Soon \\

Input :

Enter the size of array
5
Enter the elements of array
5
4
3
2
1

Output :

The sorted array is -->1
The sorted array is -->2
The sorted array is -->3
The sorted array is -->4
The sorted array is -->5

No comments:

Post a Comment