fork download
  1. program ideone;
  2. type TFunc = function (x:Real):Real;
  3.  
  4. function trapezoid(f:TFunc;a,b:Real;n:longint):Real;
  5. var k:longint;
  6. s,h:Real;
  7. begin
  8. s := f(a) + f(b);
  9. h := (b-a)/n;
  10. for k := 1 to n - 1 do
  11. s := s + 2 * f(a + k * h);
  12. trapezoid := 0.5 * s * h;
  13. end;
  14.  
  15. function f1(x:Real):Real;
  16. begin
  17. f1 := ln(1+x)/(1+sqr(x));
  18. end;
  19.  
  20. function f2(x:Real):Real;
  21. begin
  22. f2 := ln(sin(x))*ln(cos(x))/sin(2*x);
  23. end;
  24.  
  25. var a,b:Real;
  26. n:longint;
  27.  
  28. begin
  29. (* your code goes here *)
  30. readln(a,b);
  31. readln(n);
  32. writeln(trapezoid(f2,a,b,n):1:10);
  33. end.
  34.  
Success #stdin #stdout 0.13s 9128KB
stdin
1e-7 1.5707963
1000000
stdout
0.1502571129