fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. double a = 0.0;
  9. double b = 1.57;
  10. int n = 10;
  11.  
  12. double h = (b - a) / n;
  13. double S = 0.0;
  14.  
  15. S += sin(a) + sin(b);
  16.  
  17. for (int i = 1; i < n; i++)
  18. {
  19. double x = a + i * h;
  20. S += 2 * sin(x);
  21. }
  22.  
  23. S *= h / 2;
  24.  
  25. cout << "Przyblizona wartosc pola (metoda trapezow) S = " << S << endl;
  26.  
  27. return 0;
  28. }
  29.  
  30.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Przyblizona wartosc pola (metoda trapezow) S = 0.99715