//Bubble Sort
#include<stdio.h>
int swap_cnt, comp_cnt;
void bubble_sort(int a[20], int n)
{
int i, temp, pass;
comp_cnt=0, swap_cnt=0;
for(pass=1; pass<n; pass++)
{
for(i=0; i<=n-pass-1; i++)
{
comp_cnt++;
if(a[i]>a[i+1])
{
swap_cnt++;
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}//if
}//inner for
}//outer for
}//function
void main()
{
int a[20], n, i;
printf("\n How Many Number In Array=");
scanf("%d",&n);
printf("Enter a element of array:");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
bubble_sort(a, n);
printf("\n >>Sorted Element Are<< \n");
for(i=0; i<n; i++)
printf("%d\t", a[i]);
printf("\n Number of comp_cnt are: %d \n", comp_cnt);
printf("\n Number of swap_cnt are: %d \n", swap_cnt);
}