Advertisement
rozman50

Vaja_9

Dec 11th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // vaja_9.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. float f(float x) {
  10.  
  11. return pow(x, 2) + sin(x) + pow(x, 3);
  12. }
  13.  
  14. float integrate(float a, float b, float h = 0.005) {
  15. float result = 0;
  16. for (float x = a; x < b; x+=h) {
  17. result += (f(x) + f(x + h)) / 2 * h;
  18. }
  19.  
  20. return result;
  21. }
  22.  
  23. int main()
  24. {
  25. float result = 0;
  26. int a;
  27. int b;
  28. int h = 0.005;
  29.  
  30. cin >> a;
  31. cin >> b;
  32. cout << "H: " << integrate(a, b);
  33.  
  34. }
  35.  
  36. /*
  37. i(x) = SUM (a do b) = (f(x)+f(x+i))/2 * h
  38. h = x(i+1) - x(i)
  39.  
  40. n = (b-a) / h
  41. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement