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