fork(1) 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. var a,b:Real;
  21. n:longint;
  22.  
  23. begin
  24. (* your code goes here *)
  25. readln(a,b);
  26. readln(n);
  27. writeln(trapezoid(f1,a,b,n):1:10);
  28. end.
  29.  
Success #stdin #stdout 0.03s 9128KB
stdin
0 1
1000000
stdout
0.2721982613