avukas

Untitled

Apr 5th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int fun(int, int);
  6. template <typename tip>
  7. tip Integral_funkcije(tip a, tip b, tip n, tip fun(tip)){
  8. tip suma1=fun(a);
  9. tip suma2=fun(b);
  10. tip suma3(0);
  11. for(int i(0); i<n-1; i++)
  12. {
  13. suma3+=fun(((a+(b-a)/n))*i);
  14. }
  15.  
  16. tip suma=((b-a)/n)*((1/2)*suma1+(1/2)*suma2+suma3);
  17.  
  18. return suma;
  19. }
  20.  
  21. int fun(int x){
  22. return x;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28.  
  29. cout << Integral_funkcije(1,2,100, fun);
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment