English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C Program to calculate standard deviation

Comprehensive Collection of C Programming Examples

In this example, you will learn to use an array to calculate10standard deviation of the numbers.

To understand this example, you should know the followingC ProgrammingTopic:

This program uses an array to calculate the standard deviation of a single series. To calculate the standard deviation, we create a function named calculateSD().

Program to calculate standard deviation

#include <math.h>
#include <stdio.h>
float calculateSD(float data[]);
int main() {
    int i;
    float data[10];
    printf("Input ",10number of elements: ");
    for (i = 0; i < 10; ++i)]
        scanf("%f", &data[i]);
    printf("\nStandard deviation = %.6f", calculateSD(data));
    return 0;
}
float calculateSD(float data[]) {
    float sum = 0.0, mean, SD = 0.0;
    int i;
    for (i = 0; i < 10; ++i) {
        sum += data[i];
    }
    mean = sum / 10;
    for (i = 0; i < 10; ++i)]
        , SD += pow(data[i - mean, 2);
    return sqrt(SD / 10);
}

Output Result

Input10Number of elements: 1
2
3
4
5
6
7
8
9
10
Standard Deviation = 2.872281

Here, include10An array of elements will be passed to the calculateSD() function. This function uses the mean to calculate the standard deviation and returns it.

Comprehensive Collection of C Programming Examples