Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // vaja_9.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include <iostream>
- using namespace std;
- float f(float x) {
- return pow(x, 2) + sin(x) + pow(x, 3);
- }
- float integrate(float a, float b, float h = 0.005) {
- float result = 0;
- for (float x = a; x < b; x+=h) {
- result += (f(x) + f(x + h)) / 2 * h;
- }
- return result;
- }
- int main()
- {
- float result = 0;
- int a;
- int b;
- int h = 0.005;
- cin >> a;
- cin >> b;
- cout << "H: " << integrate(a, b);
- }
- /*
- i(x) = SUM (a do b) = (f(x)+f(x+i))/2 * h
- h = x(i+1) - x(i)
- n = (b-a) / h
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement