- Related Questions & Answers
- C program to calculate the standard deviation
- C++ program to implement standard deviation of grouped data
- PHP program to find standard deviation of values within an array
- Print the standard deviation of Pandas series
- Plot mean and standard deviation in Matplotlib
- How to create boxplot using mean and standard deviation in R?
- How to find mean and standard deviation from frequency table in R?
- Program for Mean Absolute Deviation in C++
- Box plot with min, max, average and standard deviation in Matplotlib
- How to find the standard deviation for rows in an R data frame?
- How to divide the data frame rows in R by row standard deviation?
- C program to calculate age
- C++ Program to calculate Double Integration
- C++ Program to implement standard error of mean
- How to find the standard deviation of specific columns in a dataframe in Pandas Python?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Standard deviation is the measure of how spread out the numbers in the data are. It is the square root of variance, where variance is the average of squared differences from the mean.

A program to calculate the standard deviation is given as follows.

#include <iostream> #include <cmath> using namespace std; int main() { float val[5] = {12.5, 7.0, 10.0, 7.8, 15.5}; float sum = 0.0, mean, variance = 0.0, stdDeviation; int i; for(i = 0; i < 5; ++i) sum += val[i]; mean = sum/5; for(i = 0; i < 5; ++i) variance += pow(val[i] - mean, 2); variance=variance/5; stdDeviation = sqrt(variance); cout<<"The data values are: "; for(i = 0; i < 5; ++i) cout<< val[i] <<" "; cout<<endl; cout<<"The standard deviation of these data values is "<<stdDeviation; }

The data values are: 12.5 7 10 7.8 15.5 The standard deviation of these data values is 3.1232

In the above program, first the sum of the data values is obtained. Then the mean is found by dividing the sum by the number of elements. This is given in the following code snippet.

for(i = 0; i < 5; ++i) sum += val[i]; mean = sum/5;

The variance of the data is found by squaring the differences from the mean, adding them and then finding their average. This is shown in the following code snippet.

for(i = 0; i < 5; ++i) variance += pow(val[i] - mean, 2); variance=variance/5;

The standard deviation is found by obtaining the square root of the variance. Then all the data values and the standard deviation is displayed. This is given as follows.

stdDeviation = sqrt(variance); cout<<"The data values are: "; for(i = 0; i < 5; ++i) cout<< val[i] <<" "; cout<<endl; cout<<"The standard deviation of these data values is "<<stdDeviation;

Advertisements