- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- 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;

- Related Questions & Answers
- C program to calculate the standard deviation
- C++ program to implement standard deviation of grouped data
- Variance and Standard Deviation
- Python - Calculate the standard deviation of a column in a Pandas DataFrame
- What is Standard Deviation of Return?
- 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
- Average Returns and Standard Deviation of Securities
- How to create boxplot using mean and standard deviation in R?
- How to find mean and standard deviation from frequency table in R?
- How to divide the matrix rows by row standard deviation in R?
- Program for Mean Absolute Deviation in C++
- C program to calculate age
- Box plot with min, max, average and standard deviation in Matplotlib

Advertisements