for(j=0;j<9;j++)//由小到大排列
{
for(i=0;i<(9-j);i++)
{
if(data[i]>data[i+1])
{
temp=data[i];
data[i]=data[i+1];
data[i+1]=temp;
}
}
}
★最大值为data[9]
★最小值为data[0]
★平均值为avr:
sum=0;
for(i=0;i<10;i++)
{
sum += data[i];
}
avr = sum/10;
★超过平均值的人数为num:
num=0;
for(i=0;i<10;i++)
{
if( data[i] > avr)
{
num++;
}
}
具体实现你整理吧。
#define N 10
#include
void main(){
float point[N];
int i;
float min,max;
float sum = 0;
int up_average = 0;
printf("input 10 number:\n");
scanf("%f", &point[0]);
max = point[0];
min = point[0];
sum = point[0];
for(i = 1; i < N; i++){
scanf("%f", &point[i]);
sum += point[i];
if(point[i] < min){
min = point[i];
}
if(point[i] > max){
max = point[i];
}
}
printf("max is %f\nmin is %f\naverage is %f\n",max,min,sum / N);
for(i = 0; i < N; i++){
if(point[i] >= (sum / N)){
up_average++;
}
}
printf("up_average is %d\n",up_average);
}
max(数组)