SHARE
TWEET

Untitled

a guest Apr 19th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. y=2x*x+1                           x[2;3]
  2. #include<iostream>
  3. #include<math.h>
  4. double integral_pr(double x, double y, int dx);
  5. double integral_sim(double x, double y, int dx);
  6. double integral_tr(double x, double y, int dx);
  7. void main(void)
  8. {
  9.     double spr, str, ssim, x, y, n;
  10.     int dx, c;
  11.     scanf_s("%lf%lf%d", &x, &y, &dx);
  12.     printf("\n x=%lf y=%lfdx=%d", x, y, dx);
  13.     scanf_s("%d", &c);
  14.     switch (c)
  15.     {
  16.     case 1:
  17.     {   spr = integral_pr(x, y, dx);
  18.     break; }
  19.     case 2:
  20.     {   spr = integral_sim(x, y, dx);
  21.  
  22.     break; }
  23.  
  24.     case 3:
  25.     {spr = integral_tr(x, y, dx);
  26.     break; }
  27.  
  28.     default: {printf("Error");
  29.         getchar();
  30.         getchar(); }
  31.     }
  32.     printf("Result:\n s=%lf", spr);
  33.     getchar();
  34.     getchar();
  35. }
  36. double integral_pr(double x, double y, int dx)
  37. {
  38.     double s, x1, b;
  39.     s = 0;
  40.     b = (y - x) / dx;
  41.     for (x1 = x; x1 < y; x1 = b + x1)
  42.         s += x1*x1 * 2 + 1;
  43.     return s*b;
  44. }
  45. double integral_tr(double x, double y, int dx)
  46. {
  47.     double s, x1, b;
  48.     s = 0;
  49.     b = (y - x) / dx;
  50.     for (x1 = x; x1 < y; x1 = b + x1)
  51.         s += (x1*x1 * 2 + 1) + ((x1 + b)*(x1 + b) * 2 + 1);
  52.     return s*b / 2;
  53. }
  54. double integral_sim(double x, double y, int dx)
  55. {
  56.     double s, x1, b;
  57.     s = 0;
  58.     b = (y - x) / dx;
  59.     for (x1 = x; x1 < y; x1 = b + x1)
  60.         s += x1*x1 * 2 + 1 + 4 * ((x1 + b / 2)*(x1 + b / 2) * 2 + 1) + ((x1 + b)*(x1 + b) * 2 + 1);
  61.     return s*b / 6;
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top