64,662
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace std;
int main(){
const int MAX_ITEMS=8;
float x[MAX_ITEMS];
float average;
float sum;
cout << "Enter " << MAX_ITEMS << "numbers: ";
int i;
for(i=0;i<MAX_ITEMS;i++)
cin >> x[i];
sum=0.0;
for(i=0;i<MAX_ITEMS;i++){
sum+=x[i];
average = sum / MAX_ITEMS;
cout << " The average value is " << average << endl << endl << endl;
cout << " Table of differences between x[i] and the average." << endl;
cout << setw(4) << "next" << setw(8) << "x[next]"
<< setw(14) << "difference" << endl;
}
for(i=0;i<MAX_ITEMS;i++){
cout << setw(4) << i << setw(8) << x[i]
<< setw(14) << (x[i]-average) << endl;
}
getch();
return 0;
}