0001、选择排序法
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #define N 20 5 6 7 void main() 8 { 9 time_t ts; 10 srand((unsigned int)time(&ts)); 11 12 int a[N] = { 0 }; 13 14 for (int i = 0; i < N; i++) 15 { 16 printf("%4d", a[i] = rand() % 300); 17 } 18 19 int intmax = 0; 选择法找极值(极大值和极小值) 20 for (int i = 0; i < N; i++) 21 { 22 if (intmax < a[i]) 23 intmax = a[i]; 24 } 25 printf("\nintmax=%d \n", intmax); // intmax=261 26 27 28 system("pause"); 29 }