Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int fun(int, int);
- template <typename tip>
- tip Integral_funkcije(tip a, tip b, tip n, tip fun(tip)){
- tip suma1=fun(a);
- tip suma2=fun(b);
- tip suma3(0);
- for(int i(0); i<n-1; i++)
- {
- suma3+=fun(((a+(b-a)/n))*i);
- }
- tip suma=((b-a)/n)*((1/2)*suma1+(1/2)*suma2+suma3);
- return suma;
- }
- int fun(int x){
- return x;
- }
- int main()
- {
- cout << Integral_funkcije(1,2,100, fun);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment