fork descargar
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double pole(double a, double b, int n) {
  7. double h = (b - a) / n;
  8. double suma = 0.0;
  9.  
  10. for (int i = 0; i < n; i++) {
  11. double x_srodek = a + (i + 0.5) * h;
  12. suma += sin(x_srodek);
  13. }
  14.  
  15. return suma * h;
  16. }
  17.  
  18. int main() {
  19. double a = 0.0;
  20. double b = 3.14;
  21.  
  22. int n1 = 10;
  23. int n2 = 100;
  24.  
  25. cout << "Pole dla n = 10: " << pole(a, b, n1) << endl;
  26. cout << "Pole dla n = 100: " << pole(a, b, n2) << endl;
  27.  
  28. return 0;
  29. }
  30.  
Éxito #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Pole dla n = 10:  2.00824
Pole dla n = 100: 2.00008