Program to Calculate Standard Deviation.

Definition: Standard deviation is the measure of dispersion of a set of data from its mean. It measures the absolute variability of a distribution; the higher the dispersion or variability, the greater is the standard deviation and greater will be the magnitude of the deviation of the value from their mean.

To calculate the standard deviation, calculateSD() function is created. The array containing 10 elements is passed to the function and this function calculates the standard deviation and returns it to the main() function.

Program:-

#include <iostream.h>
#include <math.h>
#include<conio.h>
float calculateSD(float data[]);

void main()
{
clrscr();
    int i;
    float data[10];
    cout << "Enter 10 elements: ";
    for(i = 0; i < 10; ++i)
        cin >> data[i];
    cout << endl << "Standard Deviation = " << calculateSD(data);
getch();
}
float calculateSD(float data[])
{
    float sum = 0.0, mean, standardDeviation = 0.0;
    int i;
    for(i = 0; i < 10; ++i)
    {
        sum += data[i];
    }
    mean = sum/10;
    for(i = 0; i < 10; ++i)
        standardDeviation += pow(data[i] - mean, 2);
    return sqrt(standardDeviation / 10);
}
Output:-
Program to Calculate Standard Deviation.
OUTPUT!!

Post a Comment

0 Comments