Advertisement
Maksud3

Lab5(DNR)

May 17th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 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[10] = { 3.5, 7.1, 11.2, 8.5, 1.3, 4.4, 9.8, 7.1, 1.5, 10.9 };
  14.  
  15.     printf("\t\tLab5\n");
  16.  
  17.     printf("\tx\ta\t   b\t    y\n");
  18.  
  19.     for (int o = 0; o < 10; o++)
  20.     {
  21.         printf("%10.2lf", x[o]);
  22.  
  23.         if (A(x[o]) == NULL)
  24.         {
  25.             printf("NULL");
  26.         }
  27.         else {
  28.             printf("%10.2lf", A(x[o]));
  29.         }
  30.  
  31.         if (B(x[o]) == NULL)
  32.         {
  33.             printf("NULL");
  34.         }
  35.         else {
  36.             printf("%10.2lf", B(x[o]));
  37.         }
  38.  
  39.         if (Y(A(x[o]), B(x[o])) == NULL)
  40.         {
  41.             printf("NULL");
  42.         }
  43.         else {
  44.             printf("%10.2lf\n", Y(A(x[o]), B(x[o])));
  45.         }
  46.     }
  47. }
  48.  
  49. double A(double x)
  50. {
  51.     if (x > 0)
  52.     {
  53.         double a = pow(pow(K, -1 / 2) - L * sqrt(x + 2.84), 2);
  54.         return a;
  55.     }
  56.     else {
  57.         return NULL;
  58.     }
  59. }
  60.  
  61. double B(double x)
  62. {
  63.     if (x > 0)
  64.     {
  65.         double b = -log10(x) + exp(x);
  66.         return b;
  67.     }
  68.     else {
  69.         return NULL;
  70.     }
  71. }
  72.  
  73. double Y(double a, double b)
  74. {
  75.     if (a == 0 || b == 0)
  76.     {
  77.         return NULL;
  78.     }
  79.     else {
  80.         if (a > b)
  81.         {
  82.             double y = 4 * a + 3 * b / pow(a, 2) + pow(b, 2);
  83.             return y;
  84.         }
  85.         else if (a <= b)
  86.         {
  87.             double y = fabs(a - b);
  88.             return y;
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement