#include
#include
#define max 10
void print_array(int *array) {
int x;
for(x = 0; x
printf("%d, ", array[x]);
else
printf("%d\n", array[x]);
}
}
void main(){
int iarray[max];
int x,y;
int temp;
// Seed rand()
srand((unsigned int)time(NULL));
for(x = 0; x < max; x++)
iarray[x] = (int)(rand() % 100);
//print_array(iarray);
printf("initial data\n");
print_array(iarray);
// Bubble sort method.
for(x = 0; x < max; x++){
for(y = 0; y < max-1; y++)
if(iarray[y] > iarray[y+1]) {
temp = iarray[y+1];
iarray[y+1] = iarray[y];
iarray[y] = temp;
}
printf("\n round %d\n",x);
print_array(iarray);
}
printf("\n result\n");
print_array(iarray);
}
No comments:
Post a Comment