Maksud3

Lab4(DNR)

May 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3.  
  4. const double K = 22.5;
  5. const double L = 7.5;
  6.  
  7. double A(double x);
  8. double B(double x);
  9. double Y(double a, double b);
  10.  
  11. int main(void)
  12. {
  13.     double x[3] = { 0.324, 1.426, -0.414 };
  14.  
  15.     printf("\tLab4\n");
  16.  
  17.     for (int o = 0; o < 3; o++)
  18.     {
  19.         if (A(x[o]) == NULL)
  20.         {
  21.             printf("a = invalid x, must be more than 0, where x = %lf\n", x[o]);
  22.         }
  23.         else {
  24.             printf("a = %lf, where x = %lf\n", A(x[o]), x[o]);
  25.         }
  26.  
  27.         if (B(x[o]) == NULL)
  28.         {
  29.             printf("b = Invalid x, must be more than 0, where x = %lf\n", x[o]);
  30.         }
  31.         else {
  32.             printf("b = %lf, where x = %lf\n", B(x[o]), x[o]);
  33.         }
  34.  
  35.         if (Y(A(x[o]), B(x[o])) == NULL)
  36.         {
  37.             printf("y = Invalid x, must be more than 0, where x = %lf\n", x[o]);
  38.         }
  39.         else {
  40.             printf("y = %lf, where x = %lf\n", Y(A(x[o]), B(x[o])), x[o]);
  41.         }
  42.     }
  43. }
  44.  
  45. double A(double x)
  46. {
  47.     if (x > 0)
  48.     {
  49.         double a = pow(pow(K, -1 / 2) - L * sqrt(x + 2.84), 2);
  50.         return a;
  51.     }
  52.     else {
  53.         return NULL;
  54.     }
  55. }
  56.  
  57. double B(double x)
  58. {
  59.     if (x > 0)
  60.     {
  61.         double b = -log10(x) + exp(x);
  62.         return b;
  63.     }
  64.     else {
  65.         return NULL;
  66.     }
  67. }
  68.  
  69. double Y(double a, double b)
  70. {
  71.     if (a == 0 || b == 0)
  72.     {
  73.         return NULL;
  74.     }
  75.     else {
  76.         if (a > b)
  77.         {
  78.             double y = 4 * a + 3 * b / pow(a, 2) + pow(b, 2);
  79.             return y;
  80.         }
  81.         else if(a <= b)
  82.         {
  83.             double y = fabs(a - b);
  84.             return y;
  85.         }
  86.     }
  87. }
Add Comment
Please, Sign In to add comment