为什么找不出最大值啊?
#include<stdio.h>void main()
{
int j, i,a[11]={1,8,4,7,9,3,6,4,5,3,33};
for(i=1;i<11;i++)
{
for(j=i;j<11;j++)
if(a[j]>a[i])
printf("%6d",a[j]);
}
}
#include <stdio.h> #define swap(a, b) int temp; temp = (a); (a) = (b); (b) = temp; sort_desc(int * ar, int size) { int i, j, k; for(i = 0; i < size - 1; i++) { k = i; for(j = i + 1; j < size; j++) { if(ar[j] > ar[k]) { k = j; } } if(k != i) { swap(ar[k], ar[i]); } } } int main(void) { int a[11]={1, 8, 4, 7, 9, 3, 6, 4, 5, 3, 33}; sort_desc(a, 11); printf("Max : %d\n", a[0]); return 0; }