Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int polynomial1(int* coff, int n, int x)
- {
- int xsq = 1;
- int val = 0;
- for (int ord = 0; ord <= n; ord++) {
- val += xsq * coff[ord];
- xsq *= x;
- }
- return val;
- }
- int polunomial2(int* coff, int n, int x)
- {
- int val = coff[n];
- for (int i = n - 1; i >= 0; i--) {
- val = val * x + coff[i];
- }
- return val;
- }
- int main()
- {
- int coff1[] = { 1, 2, 1 };
- int n = 2;
- cout << polynomial1(coff1, n, 1) << " " << polynomial1(coff1, n, 2) << endl;
- int coff2[] = { 1, 2 };
- n = 1;
- cout << polynomial1(coff2, n, 1) << " " << polynomial1(coff2, n, 2) << endl;
- int coff3[] = { 2 };
- n = 0;
- cout << polynomial1(coff3, n, 1) << " " << polynomial1(coff3, n, 2) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement