R0M41K

polinom

Apr 8th, 2019
51
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. #include "windows.h"
  4. using namespace std;
  5. void SetColor(int text, int background)
  6. {
  7. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  8. SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
  9. }
  10. int main() {
  11. setlocale(0,"");
  12. int n;
  13. double a[100], x, p = 0;
  14. cout << "Поліном Р(х)=an*x^n+a(n-1)*x^(n-1)+...a1*x+a0";
  15. do {
  16. cout << "\nКількість елементів масиву = ";
  17. cin >> n;
  18. } while (n <= 0 || n > 99);
  19. for (int i = 0; i < n; i++) {
  20. cout << 'a' << i+1 << "= ";
  21. cin >> a[i];
  22. }
  23. for (int i = 0; i < n; i++) {
  24. SetColor(4,0);cout << a[i] << '\t';SetColor(7,0);
  25. }
  26. cout << "\nВведіть дійсне число х = ";SetColor(5,0);
  27. cin >> x;SetColor(4,0);
  28. for (int i = 0; i < n; i++) {
  29. p += a[i] * pow(x, i);
  30. if (p >= 2000000000) { cout << "Переповнення!";
  31. break;}
  32. }
  33. cout << "P(" << x << ')' << '=' << p;SetColor(7,0);
  34. return 0;
  35. }
Add Comment
Please, Sign In to add comment