//This code is written by Souvik Ghosh
#include <stdio.h>
//Function for input array elements
void input(int *p, int size)
{
for (int i = 0; i < size; i++)
{
scanf("%d", &p[i]);
}
}
//Function for output array elements
void output(int *p, int size)
{
for (int i = 0; i < size; i++)
{
printf("%d ", p[i]);
}
printf("\n");
}
//Bubble Sort Function
void bubbleSort(int *p, int size)
{
int flag = 1;
for (int i = 0; i < size - 1; i++)
{
flag = 0;
for (int j = 0; j < size - i - 1; j++)
{
if (p[j] > p[j + 1])
{
int t = p[j];
p[j] = p[j + 1];
p[j + 1] = t;
flag = 1;
}
}
if (flag == 0)
{
break;
}
}
}
void main()
{
int size;
printf("How many elements you want to enter?\n");
scanf("%d", &size);
int sgg[size];
printf("Enter the elements\n");
input(sgg, size);
printf("Before Sorting:\n");
output(sgg, size);
bubbleSort(sgg, size);
printf("After Sorting:\n");
output(sgg, size);
}