1.功能介绍
利用数组来求解输入的十个数的和、平均值
2.代码展示
#include <stdio.h>
#define SIZE 10
#define PAR 72
int main(void)
{
int index,score[SIZE];
int sum=0;
float average;
printf("Enter %d golf scores:\n",SIZE);
for (index=0;index<SIZE;index++) //数据
scanf("%d",&score[index]);
printf("The scores read in are as follow:\n");
for(index=0;index<SIZE;index++)
printf("%5d",score[index]); //显示输入的数组的数据
printf("\n");
for(index=0;index<SIZE;index++)//循环计算
sum+=score[index];//sum的求解
average=(float)sum/SIZE;//平均数求解
printf("Sum of scores=%d,average=%.2f\n",sum,average);
printf("That's a handicap of %.0f.\n",average - PAR);
return 0;
}
3.结果展示