#include <stdio.h>
#include <time.h>
#define MAX 5
int main() {
int i, j, k, flag = 1;
int number[MAX] ;
int temp ;
srand((unsigned)time(NULL)) ;
printf("排序前: ");
for(i = 0; i < MAX; i++) {
number[i] = rand()%100 ;
printf("%3d", number[i]) ;
}
printf("\n") ;
for(i = 0; i < MAX-1; i++) {
for(j = 0; j < MAX-i-1; j++) {
if(number[j+1] < number[j]) {
temp = number[j+1] ;
number[j+1] = number[j] ;
number[j] = temp ;
}
}
printf("第 %d 次排序:", i+1);
for(k = 0; k < MAX; k++)
printf("%d ", number[k]);
printf("\n");
}
system("pause") ;
return 0 ;
}
沒有留言:
張貼留言