/*打印该数组, 逆序输出该数组
* 求该数组的平均值
*找出该数组中最大的元素 */
#include<stdio.h>
#define SIZE 10
int main(void)
{
int array[SIZE];
int i,max;
float sum=0,avg;
printf("Please input the numbers:\n");
for ( i=0; i<SIZE; i++)
{
scanf("%d",&array[i]);
sum+=array[i];
}
max=array[0];
avg=sum/SIZE;
printf("Output the array:\n");
for ( i=0; i<SIZE; i++)
{
printf("%4d",array[i]);
if ( max<=array[i] )
{
max=array[i];
}
}
printf("\n逆序输出:\n");
for ( i=SIZE-1; i>=0; i--)
{
printf("%4d",array[i]);
}
printf("\nThe max =%d\nThe avg of this array is:%f\n",max,avg);
return 0;
}
|
|