Question #37472

Exercise 1: Stadard Diviation
Use the predefined functions pow() and sqrt(). Write a program that prompts the user to input 5
numbers and outputs their standard deviation. The standard deviations s of 5 numbers x1, x2,x3,x4,
and x5is given by:









where

Expert's answer

```

// Answer on Question#37472 - Programming - C++


#include <iostream>
#include <math.h>
#include <conio.h>
using namespace std;
int main() {
    float x[5];
    int numbersAmount = 5; // beginning amount of numbers
    for (int i = 0; i < numbersAmount; i++) { // input numbers
        cout << "Enter the " << i + 1 << " number: ";
        cin >> x[i];
        cout << endl;
    }
    float average;
    average = (x[0] + x[1] + x[2] + x[3] + x[4]) / numbersAmount; // find average
    float xx[5];
    float sum = 0;
    for (int i = 0; i < numbersAmount; i++) { // calculate the difference of each data point
        xx[i] = x[i] - average;
        xx[i] = pow(xx[i], 2);
        sum += xx[i];
    }
    float standardDeviation;
    standardDeviation = sqrt(sum / (numbersAmount - 1));
    cout << "Standard Deviation of your 5 numbers is: " << standardDeviation << endl;
    _getch();
    return 0;
}

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!

LATEST TUTORIALS
APPROVED BY CLIENTS