C program to implement Bubble Sort

Simple C program to implement Bubble Sort Algorithm

Code:

#include<stdio.h>



int main()

{

int a[50],n,i,j,temp;

printf("Enter the size of array: ");

scanf("%d",&n);

printf("Enter the array elements: ");



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

scanf("%d",&a[i]);



for(i=1;i<n;++i)

for(j=0;j<(n-i);++j)

if(a[j]>a[j+1])

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}



printf("\nArray after sorting: ");

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

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



return 0;

}

Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

C++ program to perform data transformation Min-max and Z score Normalization

Java Program to Implement sorting algorithm using TCP on Server application