int main (void) { int arr[ARRAY_LEN],max,min; float sum,average; int i;
printf ("请为%d个元素的一维数组输入内容:\n",ARRAY_LEN); for (i=0; i<ARRAY_LEN; i++) scanf ("%d",&arr[i]); putchar ('\n');
min = max = arr[0]; sum = average = 0; for (i=0; i<ARRAY_LEN; i++) { if (arr[i]<min) min = arr[i]; if (arr[i]>max) max = arr[i]; sum += arr[i]; } average = sum/ARRAY_LEN;
运行结果
#include<stdio.h>
int main()
{int i,max,min,s=0,a[10]={12,4,13,53,57,85,52,66,59,90};
max=min=a[0];
for(i=1;i<10;i++)
{s+=a[i];
if(a[i]>max)max=a[i];
else if(a[i]<min)min=a[i];
}
printf("最大值=%d\n最小值=%d\n平均值=%.2f\n",max,min,s/10.0);
return 0;
}
一周热门 更多>