Advertisement
NyanCoder

Gorner.c

May 15th, 2022
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3.  
  4. float Gorner(float* arr, float x, int n) {
  5.     float result = arr[n], f = 1;
  6.     for (int i = 1; i <= n; i++) {
  7.         f = f * x;
  8.         result += arr[n - i] * f;
  9.     }
  10.     return result;
  11. }
  12.  
  13. int main(int argc, char** argv) {
  14.     int n = 0;
  15.     printf("Введите n=");
  16.     scanf("%d", &n);
  17.     float x = 0;
  18.     printf("Введите x=");
  19.     scanf("%f", &x);
  20.     printf("Введите %d коэфф. многочлена степени %d", n + 1, n);
  21.     float* arr = (float*)malloc(sizeof(float) * (n + 1));
  22.     for (int i = 0; i <= n; i++)
  23.         scanf("%f", &arr[i]);
  24.     printf("S=%f", Gorner(arr, x, n));
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement