Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- double TrapeznoPravilo(double f(double), int a, int b, int n)
- {
- double suma(0);
- for(int i(1); i <= n - 1; i++)
- suma+=f(a + ((double(b-a)/n)*i));
- return ((double(b-a)/n)*(f(double(a))/2 + f(double(b))/2 + suma));
- }
- int main()
- {
- std::cout << TrapeznoPravilo([](double x) {return x*x*x;}, 0, 10, 200) << std::endl;
- std::cout << TrapeznoPravilo([](double x) {return std::sin(x);}, 0, 4*atan(1), 200) << std::endl;
- std::cout << TrapeznoPravilo([](double x) {return 1./x;}, 1, 2, 200) << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement