Tutorials
Population Standard Deviation Program in C++ With Explanation

Before jumping to the Standard Deviation Program in C++, we will discuss the Standard Deviation. So, The Standard Deviation is the measure of how spread out numbers are. It is denoted by a Greek symbol Sigma σ (The Greek Letter Sigma). If you want to learn more about Standard Deviation, Check this on Wikipedia.
Suggested Post: How To Find My iPhone? When It’s Lost or Stolen
Formula of Standard Deviation:

= | Population Standard Deviation | |
= | The Size of the Population | |
= | Each Value From The Population | |
= | The Population Mean |
Standard Deviation Program in C++:
#include <iostream>
//Header File
#include <cmath>
//Header File
using namespace std;
//Header File
//Function To do Calculations
float sqrt(float data[], int N)
//Function To do Calculations
{
//Variables
float sigma = 0.0, meanValue, standardDeviation = 0.0;
int i;
//Calculating the Sigma Σ (Sum of All Data Input)
for (i = 1; i <= N; ++i)
{
sigma += data[i];
}
//Calculating the Mean Value
meanValue = sigma / N;
//Calculating the Varience
for (i = 1; i <= N; ++i)
standardDeviation += pow(data[i] - meanValue, 2);
//Returning Std Deviation
return sqrt(standardDeviation / N);
}
int main()
{
// variables
int i, N;
float data[50];
float result;
//Taking Input
cout << "How much data figures you want to enter = ";
cin >> N;
for (i = 1; i <= N; ++i) {
cout << "Enter " << i << " elements: ";
cin >> data[i];
}
//Taking and sending data to Sqrt Function
result = sqrt(data,N);
//Showing Result
if (result != 0 || result == 0) {
cout << "The data values are: ";
for (i = 1; i <= N; ++i)
cout << data[i] << " ";
cout << endl;
cout << "The standard deviation of these data values is " << result;
}
else
{
cout << "Error Found !Try Again.";
}
cout << endl;
return 0;
}
GitHub:
Grab it from GitHub. Click Here
Output:
