Answer to Question #219752 in C++ for danny

Question #219752

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


1
Expert's answer
2021-07-22T18:35:18-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS