0
845views
Write a program to evaluate the value of the standard deviation and display the result.

$Sd = \sqrt{Σ_{i = 1}^n(xi - \bar{x})^2/n}$

Where x = Average of all no is array


Mumbai university > FE > SEM 2 > Structured Programming Approach

Marks: 10M

Year: May 2014

1 Answer
0
5views
#include <stdio.h>
#include <math.h>
float standard_deviation(float data[], int n);
void main()
{
    int n, i;
    float data[100];
    printf("Enter number of datas( should be less than 100): ");
    scanf("%d",&n);
    printf("Enter elements: ");
    for(i=0; i<n; ++i)
        scanf("%f",&data[i]);
    printf("\n");
    printf("Standard Deviation is %f", standard_deviation(data,n));
    getche();
}
float standard_deviation(float data[], int n)
{
    float mean=0.0, sum_deviation=0.0;
    int i;
    for(i=0; i<n;++i)
    {
        mean+=data[i];
    }
    mean=mean/n;
    for(i=0; i<n;++i)
    sum_deviation+=(data[i]-mean)*(data[i]-mean);
    return sqrt(sum_deviation/n);           
}

Output

Enter number of datas( should be less than 100): 5

Enter elements: 1

1

1

1

1

Standard deviation is 0.000

Please log in to add an answer.