Advertisement
sellmmaahh

TP-tut5-zad4

Sep 3rd, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6. double TrapeznoPravilo (double f(double ), int a, int b, int n)  {
  7.     double suma=0;
  8.     for (int i=1; i<n; i++) {
  9.             suma+=f(a+((b-a)/n)*i);
  10.     }
  11.     suma+=(1/2)*(f(a)+f(b));
  12.     return suma*(b-a)/n;
  13. }
  14. int main () {
  15.     cout<<"Rezultat funkcije: "<<TrapeznoPravilo( [] (double x) { return x*x*x; },0,10,5);
  16.     return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement