#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int a[25] = {5,14,2,21,1,6,4,2,34,5,546,23,23,4,5,21,1,5,6,7,888};
//calculating the number of elements in array a
int n=0;
while(a[n] != '\0'){
n++;
}
// decrementing n because array index starts with 0, not 1
n--;
int swapped,temp;
for(int i=0; i < n;i++){
swapped=0;
for(int j=0;j <n-i;j++){
if (a[j] > a[j+1]){
// swapping elements
temp = a[j+1];
a[j+1] = a[j];
a[j] = temp;
swapped = 1;
}
}
// if no element has been swapped in this pass, it means the array is sorted
if (swapped ==0)
break;
}
// displaying results
n=0;
while(a[n] != '\0'){
printf("%d\n",a[n]);
n++;
}
system("PAUSE");
return 0;
}