write a program that computes the average value of an array and prints the difference between each value and the average value you have just computed let the maximum number of items in the array be 8
#include <iostream>
using namespace std;
int main() {
double arr[] = {1, 2, 9, 5, 3, 12, 11};
int n = sizeof(arr) / sizeof(arr[0]);
double avr = 0.0;
for (int i=0; i<n; i++) {
avr += arr[i];
}
avr /= n;
cout << "Difference between each value and the average value:" << endl;
for (int i=0; i<n; i++) {
cout << arr[i] - avr << " ";
}
cout << endl;
}
Comments
Leave a comment