Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>//standard input out put library.
- #include <math.h>// standard libraries for the math functions
- #include <stdlib.h>
- #define Pi 3.14159265
- double divide(double X, double Y){// prototypes and the definitions
- return X/Y;
- }
- double multiply(double num1, double num2){
- return num1*num2;
- }
- double exp(double d);
- double sub(double num1, double num2){
- return num1-num2;
- }
- double sqrt(double X);
- double pow(double X, double Y);
- int main(void) {
- double a, u, P, d, X;
- double diff;
- double div;
- double squared;
- double d2;
- double pi2;
- double sqrt1;
- double multiply1;
- double fraction;// referring to 1/a*sqrt(2pi)
- double expo;
- int tests;
- a=1.14;// "a" is the sigma.
- u=10.71;//"u" is the Mu.
- while(tests){//while loop for infinite loops.
- printf("Probability of X given Mu= %lg and Sigma= %lg \n\n",u, a);
- printf("Enter the X values: ");
- scanf("%lf",&X);
- //Steps to find what "d" is equal to
- diff=sub(X,u);//X-u.
- div=divide(diff,a);//(x-u)/a
- squared=pow(div,2);//((X-u)/a)^2
- d=divide(squared,2);//((X-u)/a)^2)/2
- d2=multiply(-1,d);//multiplies d*-1 to get -d for the exp=e^-d formula.
- //steps to find P using the X value given by the user and the value found for "d"
- pi2= multiply(2,Pi);// 2*pi
- sqrt1= sqrt(pi2);// square root of 2*pi
- multiply1=multiply(a,sqrt1);// sigma* square root of 2*pi
- fraction=divide(1,multiply1);
- expo=exp(d2);//e^-d
- P=multiply(fraction,expo);// (1/a*sqrt(2pi))*expo
- printf("\nThe probability of %lg in this distribution is \n%lg\n", X,P);
- printf("-------------------\n");
- }
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment