# C++ Program to implement standard error of mean

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

In this tutorial, we will be discussing a program to implement standard error of mean.

Standard error of mean is the estimation of sample mean dispersion from population mean. Then it is used to estimate the approximate confidence intervals for the mean.

## Example

#include <bits/stdc++.h>
using namespace std;
//calculating sample mean
float calc_mean(float arr[], int n){
float sum = 0;
for (int i = 0; i < n; i++)
sum = sum + arr[i];
return sum / n;
}
//calculating standard deviation
float calc_deviation(float arr[], int n){
float sum = 0;
for (int i = 0; i < n; i++)
sum = sum + (arr[i] - calc_mean(arr, n)) * (arr[i] - calc_mean(arr, n));
return sqrt(sum / (n - 1));
}
//calculating sample error
float calc_error(float arr[], int n){
return calc_deviation(arr, n) / sqrt(n);
}
int main(){
float arr[] = { 78.53, 79.62, 80.25, 81.05, 83.21, 83.46 };
int n = sizeof(arr) / sizeof(arr[0]);
cout << calc_error(arr, n) << endl;
return 0;
}

## Output

0.8063
Updated on 03-Dec-2019 11:25:42