Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. double fukcja(double horn[], int zspojkuj, double jakes)
  8. {
  9.  
  10. double summary = 0;
  11. for (int i = zspojkuj; i >= 0; i-1)
  12. {
  13. summary = summary * jakes + horn[i];
  14. }
  15. return summary;
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21. double epsilon0 = 0.000001;
  22. double epsilon1 = 0.000001;
  23. double tabH[11];
  24. int y, z, x;
  25. double asd,max,wymnik,f0,a,b;
  26. cin >> x;
  27. for (int i = 0; i < x; i++)
  28. {
  29.  
  30. cin >> y;
  31. if (y > 1 && y <= 10)
  32. {
  33. for (int d = 0; d <= y; d+1)
  34. {
  35. cin >> tabH[d];
  36. }
  37. cin >> z;
  38. for (int as = 0; as < z; as+1)
  39. {
  40. cin >> asd;
  41. cin >> max;
  42. a = fukcja(tabH, y, asd);
  43. b = fukcja(tabH, y, max);
  44. while (abs(a - b) > epsilon1)
  45. {
  46. wymnik = (asd + max) / 2;
  47. f0 = fukcja(tabH, y, wymnik);
  48. if (abs(f0) < epsilon0) break;
  49. if (a * f0 < 0) max = wymnik;
  50. else
  51. {
  52. asd = wymnik; a = f0;
  53. }
  54. }
  55. cout << wymnik << endl;
  56. }
  57.  
  58.  
  59. }
  60.  
  61.  
  62. }
  63. system("pause");
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement