Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- double a = Convert.ToDouble(Console.ReadLine());
- double b = Convert.ToDouble(Console.ReadLine());
- if (a >= b)
- return;
- double h = (b - a) / 10;
- double FinalS = S(a, b, h, 0);
- double Y(double x)
- {
- return Math.Sin(x);
- }
- double S(double a, double b, double h, double S_Last)
- {
- double epsilon = 0.0001;
- double s = 0;
- double x = a;
- while (x < b)
- {
- double y1 = Y(x);
- double y2 = Y(x + h);
- double dx = h;
- s += dx * (y1 + y2) / 2;
- x += h;
- }
- if (S_Last == 0 || Math.Abs(s - S_Last) > epsilon)
- {
- return S(a, b, h / 2, s);
- }
- else
- return s;
- }
- Console.WriteLine(FinalS.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement