Advertisement
AIwinter

Untitled

Jun 28th, 2022
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1.  
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             double a = Convert.ToDouble(Console.ReadLine());
  8.             double b = Convert.ToDouble(Console.ReadLine());
  9.  
  10.             if (a >= b)
  11.                 return;
  12.  
  13.             double h = (b - a) / 10;
  14.  
  15.             double FinalS = S(a, b, h, 0);
  16.             double Y(double x)
  17.             {
  18.                 return Math.Sin(x);
  19.             }
  20.  
  21.             double S(double a, double b, double h, double S_Last)
  22.             {
  23.                 double epsilon = 0.0001;
  24.                 double s = 0;
  25.                 double x = a;
  26.                 while (x < b)
  27.                 {
  28.                     double y1 = Y(x);
  29.                     double y2 = Y(x + h);
  30.                     double dx = h;
  31.                     s += dx * (y1 + y2) / 2;
  32.                     x += h;
  33.                 }
  34.                 if (S_Last == 0 || Math.Abs(s - S_Last) > epsilon)
  35.                 {
  36.                     return S(a, b, h / 2, s);
  37.                 }
  38.                 else
  39.                     return s;
  40.             }
  41.             Console.WriteLine(FinalS.ToString());
  42.         }
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement