Answer:
The program in C++ is as follows:
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int cars;
cin>>cars;
double weights[cars];
double total = 0;
for(int i = 0; i<cars;i++){
cin>>weights[i];
total+=weights[i]; }
double avg = total/cars;
for(int i = 0; i<cars;i++){
cout<<fixed<<setprecision(1)<<avg-weights[i]<<endl; }
return 0;
}
Explanation:
This declares the number of cars as integers
int cars;
This gets input for the number of cars
cin>>cars;
This declares the weight of the cars as an array of double datatype
double weights[cars];
This initializes the total weights to 0
double total = 0;
This iterates through the number of cars
for(int i = 0; i<cars;i++){
This gets input for each weight
cin>>weights[i];
This adds up the total weight
total+=weights[i]; }
This calculates the average weights
double avg = total/cars;
This iterates through the number of cars
for(int i = 0; i<cars;i++){
This prints how much weight to be added or subtracted
cout<<fixed<<setprecision(1)<<avg-weights[i]<<endl; }