Kevin321888999

lab 3 part D

Mar 9th, 2022
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. #include <stdio.h>//standard input out put library.
  2. #include <math.h>// standard libraries for the math functions
  3. #include <stdlib.h>
  4. #define Pi 3.14159265
  5.  
  6. double divide(double X, double Y){// prototypes and the definitions
  7.   return X/Y;
  8. }
  9. double multiply(double num1, double num2){
  10.   return num1*num2;
  11. }
  12. double exp(double d);
  13. double sub(double num1, double num2){
  14.   return num1-num2;
  15. }
  16. double sqrt(double X);
  17. double pow(double X, double Y);
  18.  
  19.  
  20.  
  21. int main(void) {
  22.   double a, u, P, d, X;
  23.   double diff;
  24.   double div;
  25.   double squared;
  26.   double d2;
  27.  
  28. double pi2;
  29. double sqrt1;
  30. double multiply1;
  31. double fraction;// referring to 1/a*sqrt(2pi)
  32. double expo;
  33.   int tests;
  34.   a=1.14;// "a" is the sigma.
  35.   u=10.71;//"u" is the Mu.
  36. while(tests){//while loop for infinite loops.
  37. printf("Probability of X given Mu= %lg and Sigma= %lg \n\n",u, a);
  38. printf("Enter the X values: ");
  39. scanf("%lf",&X);
  40. //Steps to find what "d" is equal to
  41. diff=sub(X,u);//X-u.
  42. div=divide(diff,a);//(x-u)/a
  43. squared=pow(div,2);//((X-u)/a)^2
  44. d=divide(squared,2);//((X-u)/a)^2)/2
  45. d2=multiply(-1,d);//multiplies d*-1 to get -d for the exp=e^-d formula.
  46.  
  47. //steps to find P using the X value given by the user and the value found for "d"
  48. pi2= multiply(2,Pi);// 2*pi
  49. sqrt1= sqrt(pi2);// square root of 2*pi
  50. multiply1=multiply(a,sqrt1);// sigma* square root of 2*pi
  51. fraction=divide(1,multiply1);
  52. expo=exp(d2);//e^-d
  53. P=multiply(fraction,expo);// (1/a*sqrt(2pi))*expo
  54. printf("\nThe probability of %lg in this distribution is \n%lg\n", X,P);
  55. printf("-------------------\n");
  56. }
  57. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment