fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. int main() {
  5. double a = 1.0;
  6. double b = 3.0;
  7. int n = 5;
  8.  
  9. double h = (b - a) / n; // długość podprzedziału
  10. double suma = 0.0;
  11.  
  12. for (int i = 0; i < n; i++) {
  13. double x = a + i * h; // lewy koniec przedziału
  14. suma += sin(x);
  15. }
  16.  
  17. double wynik = h * suma;
  18.  
  19. std::cout << "Przyblizenie calki metoda prostokatow: "
  20. << wynik << std::endl;
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Przyblizenie calki metoda prostokatow: 1.64991