Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double fukcja(double horn[], int zspojkuj, double jakes)
- {
- double summary = 0;
- for (int i = zspojkuj; i >= 0; i-1)
- {
- summary = summary * jakes + horn[i];
- }
- return summary;
- }
- int main()
- {
- double epsilon0 = 0.000001;
- double epsilon1 = 0.000001;
- double tabH[11];
- int y, z, x;
- double asd,max,wymnik,f0,a,b;
- cin >> x;
- for (int i = 0; i < x; i++)
- {
- cin >> y;
- if (y > 1 && y <= 10)
- {
- for (int d = 0; d <= y; d+1)
- {
- cin >> tabH[d];
- }
- cin >> z;
- for (int as = 0; as < z; as+1)
- {
- cin >> asd;
- cin >> max;
- a = fukcja(tabH, y, asd);
- b = fukcja(tabH, y, max);
- while (abs(a - b) > epsilon1)
- {
- wymnik = (asd + max) / 2;
- f0 = fukcja(tabH, y, wymnik);
- if (abs(f0) < epsilon0) break;
- if (a * f0 < 0) max = wymnik;
- else
- {
- asd = wymnik; a = f0;
- }
- }
- cout << wymnik << endl;
- }
- }
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement