Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- double c1(double x) {
- return sin(x);
- }
- double c2(double x) {
- return 2*sin(x);
- }
- int main()
- {
- float a, b, h, calka1, calka;
- int ilosc;
- // przedział
- a = 0;
- b = 3.14;
- ilosc = 20;
- h = (b - a) / (float)ilosc;
- cout << "krok: h=" << h << endl;
- //trapezy
- calka = 0;
- for (int i=1; i<ilosc; i++)
- {
- calka += c2(a + i * h);
- }
- calka += c2(a) / 2;
- calka += c2(b) / 2;
- calka *= h;
- //prostokaty
- calka1 = 0;
- for (int i=1; i<=ilosc; i++)
- {
- calka1 += c1(a + i*h)*h;
- }
- cout << "Wynik sin(x): " << calka1 << endl;
- cout << "Wynik 2sin(x): " << calka << endl;
- cout << "Pole pomiedzy: "<<calka-calka1<< endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement