#include <iostream>
#include <utility>
#include <cmath>
using namespace std;
double compute_by_rectangle_method(double from, double to, double precision, double (*func)(double) ) {
if(to < from){
return compute_by_rectangle_method(to, from, precision, func);
}
double accumulator = 0.0;
for(double i = from + precision; i < to; i += precision) {
accumulator += func(i);
}
return accumulator * precision;
};
int main() {
double from = 0.0; //prompt_for_double("Enter lower limit of integral: ");
double to = 1000.0; //prompt_for_double("Enter upper limit of integral: ");
double result = compute_by_rectangle_method(from, to, 1.0, [](double x){
return std::sin(x) + std::sqrt(x) * std::cos(x/3);
});
cout << result;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPGNtYXRoPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKZG91YmxlIGNvbXB1dGVfYnlfcmVjdGFuZ2xlX21ldGhvZChkb3VibGUgZnJvbSwgZG91YmxlIHRvLCBkb3VibGUgcHJlY2lzaW9uLCBkb3VibGUgKCpmdW5jKShkb3VibGUpICkgewogIGlmKHRvIDwgZnJvbSl7CiAgICByZXR1cm4gY29tcHV0ZV9ieV9yZWN0YW5nbGVfbWV0aG9kKHRvLCBmcm9tLCBwcmVjaXNpb24sIGZ1bmMpOwogIH0KICBkb3VibGUgYWNjdW11bGF0b3IgPSAwLjA7CiAgZm9yKGRvdWJsZSBpID0gZnJvbSArIHByZWNpc2lvbjsgaSA8IHRvOyBpICs9IHByZWNpc2lvbikgewogICAgYWNjdW11bGF0b3IgKz0gZnVuYyhpKTsKICB9CiAgcmV0dXJuIGFjY3VtdWxhdG9yICogcHJlY2lzaW9uOwp9OwoKaW50IG1haW4oKSB7CiAgZG91YmxlIGZyb20gPSAwLjA7ICAvL3Byb21wdF9mb3JfZG91YmxlKCJFbnRlciBsb3dlciBsaW1pdCBvZiBpbnRlZ3JhbDogIik7CiAgZG91YmxlIHRvID0gMTAwMC4wOyAvL3Byb21wdF9mb3JfZG91YmxlKCJFbnRlciB1cHBlciBsaW1pdCBvZiBpbnRlZ3JhbDogIik7CiAgZG91YmxlIHJlc3VsdCA9IGNvbXB1dGVfYnlfcmVjdGFuZ2xlX21ldGhvZChmcm9tLCB0bywgMS4wLCBbXShkb3VibGUgeCl7CiAgCXJldHVybiBzdGQ6OnNpbih4KSArIHN0ZDo6c3FydCh4KSAqIHN0ZDo6Y29zKHgvMyk7CiAgfSk7CiAgY291dCA8PCByZXN1bHQ7CiAgcmV0dXJuIDA7Cn0=