请教数值排序问题
在贴吧看到的一道题,没能做出来,问问大家哈
程序代码:
#include <stdio.h> #include <stdlib.h> void tra_arr(int * a, int len); float get_average(int a[], int length); void get_arrb(int a[], int length, int t); int main( void ) { int a[20] = {0}; int i; float average = 0.0; printf("please you input the 20 number:\n"); for( i = 0; i < 20; i++)//输入元素 { scanf("%d", &a[i]); } printf("The a arr:\n"); tra_arr(a, 20); printf("\n"); average = get_average(a, 20); printf("The average is %f\n", average); get_arrb(a, 20, average); system("pause"); return 0; } void tra_arr(int a[], int length)//遍历数组 { int i; for( i = 0; i < length; i++ ) { printf("%d\t", a[i]); } } float get_average(int a[], int length) { float average = 0.0; int i; int sum = 0; for ( i = 0; i < length; i++ ) { sum += a[i]; } average = 1.0 * sum / length; return average; } void get_arrb(int a[], int length, int t) { int i; int n = 0; int temp; for (i = 0; i < length; i++ ) { if (t > a[i]) { n++; printf("%d\t", a[i]);//目前卡在这里,我只能找出小于平均值的数,实现不了排序 } } printf("%d\n", n); }