fork download
  1. #include <bits/stdc++.h>
  2. int main() {
  3. int a,b,c,d; std::cin >> a >> b >> c >> d;
  4. auto p = [&](int x) {
  5. // calculate p(x) = a*x^3+b*x^2+c*x+d
  6. // coefficients a,b,c,d is captured from local scope
  7. return d + x * (c + x * (b + x * 1LL * a));
  8. };
  9. for (int x = -5; x <= 5; x++) std::cout << p(x) << ' ';
  10. }
Success #stdin #stdout 0s 4404KB
stdin
1 3 3 1
stdout
-64 -27 -8 -1 0 1 8 27 64 125 216