#include <stdio.h>
typedef int Item;
#define key(A) (A)
#define less(A, B) (key(A) < key(B))
#define more(A, B) (key(A) > key(B))
#define exch(A, B) {Item t = A; A = B; B = t;}
#define compexch(A, B) if (less(B, A)) exch(A, B)
int main(void)
{
int a[10] = {1, 3, 8, 7, 9, 9, 4, 6, 8, 10};
int i, j, max;
for (i = 0; i < 4; i++)
{
max = i;
for(j = i + 1; j <= 10-1; j++)
{
if(more(a[j], a[max]))
max = j;
}
exch(a[i], a[max]);
}
for (i = 0; i < 4; i++)
{
printf("%d ", a[i]);
}
getchar();
return 0;
}
[
本帖最后由 BlueGuy 于 2010-9-11 12:26 编辑 ]