Advertisement
pVinc

Untitled

Apr 7th, 2021
521
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cmath>
  2. #include <iostream>
  3.  
  4. #define scanf_s(x, y) scanf(x, y)
  5.  
  6. double wP(double x, double *a, int n) {
  7.   double w = 0;
  8.   for (int k = 0; k <= n; k++) {
  9.     w = w + a[k] * pow(x, k);
  10.   }
  11.   return w;
  12. }
  13. double wH(double x, double *a, int n) {
  14.   double w = 0;
  15.   w = a[n];
  16.   for (int k = n - 1; k >= 0; k--) {
  17.     w = w * x + a[k];
  18.   }
  19.   return w;
  20. }
  21.  
  22. int main() {
  23.   int n;
  24.   printf("Podaj stopień wielomianu (int>=0) n = ");
  25.   scanf_s("%d", &n);
  26.   printf("\t podano n = %d\n", n);
  27.  
  28.   double *a_wek_dyn = new double[n + 1];
  29.   for (int i = 0; i <= n; i++) {
  30.     a_wek_dyn[i] = 0.5 / (i + 2.0);
  31.     printf("a[%d]=%lf", i, a_wek_dyn[i]);
  32.     printf("\n");
  33.   }
  34.   printf("\n");
  35.   for (double x = -2.5; x <= 2.5; x += (5.0 / n / 2.0)) {
  36.     printf("wP[%lf]=%lf", x, wP(x, a_wek_dyn, n));
  37.     printf("\n");
  38.     printf("wH[%lf]=%lf", x, wH(x, a_wek_dyn, n));
  39.     printf("\n\n");
  40.   }
  41. }
  42.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement