Question

4. Write a C++ program Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are xi, Xa, x3, Xa, and xs, then the mean is x = (Xi + X2 + X3+ X4 + Xs)/5 and the standard deviation is: Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation. 30 pts
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int array[5];
     for(int i = 0; i < 5 ; i++) {
          cin >> array[i];
     } 
   cout<<"Mean value is "<<getMean(array);
 
   cout<<"The standard deviation is "<<getStandardDeviation(array);    
}

float getMean(int array[ ]){

 float sum = 0.0, mean;
 for(i = 0; i < 5; ++i){
      sum += array[i];
 }
      mean = sum/5;

return mean;

}

float getStandardDeviation(int array[ ]){

float variance = 0.0, stdDeviation;

     for(i = 0; i < 5; ++i){
      variance += pow(array[i] - mean, 2);
      }
      variance=variance/5;
      stdDeviation = sqrt(variance);

return stdDeviation;

}

Add a comment
Know the answer?
Add Answer to:
4. Write a C++ program Write a program that takes as input five numbers and outputs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT