# Day 6: The Central Limit Theorem III | 10 Days Of Statistics | HackerRank Solution

Hello coders, today we are going to solve Day 6: The Central Limit Theorem III HackerRank Solution which is a Part of 10 Days of Statistics Series.

## Objective

In this challenge, we practice solving problems based on the Central Limit Theorem.

You have a sample of 100 values from a population with mean u = 500 and with standard deviation o = 80. Compute the interval that covers the middle 95% of the distribution of the sample mean; in other words, compute A and B such that P(A < x < B) = 0.95. Use the value of z = 1.96. Note that  is the z-score.

## Input format

There are five lines of input (shown below):

``````100
500
80
.95
1.96``````

The first line contains the sample size. The second and third lines contain the respective mean (u) and standard deviation (o). The fourth line contains the distribution percentage we want to cover (as a decimal), and the fifth line contains the value of z.

If you do not wish to read this information from stdin, you can hard-code it into your program.

## Output Format

Print the following two lines of output, rounded to a scale of 2 decimal places (i.e., 1.23 format):

1. On the first line, print the value of A.
2. On the second line, print the value of B.

## Solution – The Central Limit Theorem III

### C++

```#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

double normal_dist(double m, double sd, double x)
{
double p = 0.5*(1 + erf((x-m)/(sd*sqrt(2.0))));
return p ;
}

int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */

double mean = 500;
double std = 80;
int n = 100;
double zScore = 1.96;

double marginOfError = zScore * std/sqrt(n);

printf("%0.2f\n%0.2f", mean - marginOfError, mean + marginOfError);

return 0;
}```

Disclaimer: The above Problem (The Central Limit Theorem III) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.