fork download
  1. #include <stdio.h>
  2.  
  3. float polyn(float a[], int n, float x) {
  4. float acc = a[n - 1];
  5. for (int i = n - 1; i >= 1; i--)
  6. acc = acc * x + a[n - 1];
  7. return acc;
  8. }
  9.  
  10. int main(void) {
  11. float coeffs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  12. printf("%f\n", polyn(coeffs, 9, 1));
  13. printf("%f\n", polyn(coeffs, 9, 2));
  14. printf("%f\n", polyn(coeffs, 9, 3));
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
9.000000
511.000000
9841.000000