#include
int main()
{
int a[6];
int i;
double sum=0,avg;
for(i = 0;i < 6;i++){
scanf("%d",&a[i]);
sum += a[i];
}
avg = sum/6;
printf("sum = %.0lf average = %.1lf\n",sum,avg);
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
float a[6], t = 0, p;
cout << "请输入6个数据,以空格隔开:";
cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];//不固定的话就使用循环。这里代码运行效率更高
int i;
for (i = 0; i < 6; i++)
{
t += a[i];
}
p = t / 6.0f;
cout << endl << "总和:" << t;
cout << endl << "平均值:" << p;
system("pause"); //让窗口暂停,便于看结果
return 0;
}