#include <stdio.h>
#include <stdlib.h>
void bubble_sort(int a[], int size);
void print_array(int a[], int size);
int main()
{
int size;
int i;
int *a;
printf("input the size of array: size = ");
scanf("%d",&size);
a = (int *)malloc(size * sizeof(int));
for(i=0; i < size; i++)
{
printf("input the %dth element of array's value : a[%d] = ",i+1,i);
scanf("%d",&a[i]);
printf(" ");
}
print_array(a, size);
bubble_sort(a, size);
print_array(a, size);
return 0;
}
void print_array(int a[], int size)
{
int i;
for(i = 0; i < size; i++)
{
printf(" %d ",a[i]);
}
printf(" ");
}
void bubble_sort(int a[], int size)
{
int i;
int temp;
int exchange = size -1;
int bound;
while(exchange)
{
bound = exchange;
exchange = 0;
isend = 0;
for(i = 0; i < bound; i++)
{
if(a[i] > a[i+1])
{
temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
exchange = i;
}
}
print_array(a,size);
}
}