Advertisement
Cherro

Horner

Nov 8th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define N 6
  5. int main()
  6. {
  7.     int tab[N];
  8.     int x;
  9.     set_tab(&tab,N);
  10.     get_num(&x,1,0);
  11.     printf("Horner: %d",horner(&tab,N,x));
  12.  
  13.     return 0;
  14. }
  15.  
  16. void get_num(int *num,int variant,int txt)
  17. {
  18.     if(variant == 0)
  19.     {
  20.         printf("Podaj wartosc wspolczynnika nr %d\n",txt);
  21.         scanf("%d",num);
  22.     }
  23.  
  24.     if(variant == 1)
  25.     {
  26.         printf("Podaj wartosc x\n ");
  27.         scanf("%d",num);
  28.     }
  29.  
  30. }
  31.  
  32.  
  33.  
  34. void set_tab(int *tab,int n)
  35. {
  36.     int i;
  37.     for(i=0;i<n;i++)
  38.       get_num(tab+i,0,i);
  39.  
  40.  
  41.  
  42.  
  43.  
  44. }
  45.  
  46. int horner(int *tab,int n, int x)
  47. {
  48.     int horner_effect=0;
  49.     int i;
  50.     for(i=0;i<n;i++)
  51.         horner_effect=horner_effect*x + tab[i];
  52.  
  53.     return horner_effect;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement