Skip to content

Commit

Permalink
Create Day-5_NormalDistribution-I.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SrGrace authored Nov 8, 2017
1 parent 954c1b7 commit 2f10231
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Day-5/Day-5_NormalDistribution-I.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@


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


/*
given,
mean = 20 hrs
std_d = 2 hrs
*/

double normal_dist(double m, double sd, double x)
{
//return (1/(s*(sqrt(2*3.14))))*(pow(2.17, (-((x-m)*(x-m))/(2*s*s))));

/*
p = 1/2*(1 + erf((x - m)/(sd*sqrt(2))));
*/

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 m = 20, sd = 2, x = 19.5, a = 20, b = 22;

double p1 = normal_dist(m, sd, x);
double p2 = normal_dist(m, sd, b) - normal_dist(m, sd, a);

printf("%0.3f\n%0.3f", p1, p2);

return 0;
}



0 comments on commit 2f10231

Please sign in to comment.