Advertisement
Cherro

Untitled

Jan 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int horner(int wsp[],int st, int x);
  5. int main()
  6. {
  7. int *wspolczynniki;
  8. int stopien, argument;
  9.  
  10. puts("Podaj stopien wielomianu: ");
  11. scanf("%d",&stopien);
  12.  
  13. wspolczynniki = malloc(stopien+1*sizeof(int));
  14.  
  15. //wczytanie współczynników
  16. int i;
  17. for(i=0;i<=stopien;i++)
  18. {
  19. printf("Podaj wspolczynnik stojacy przy potedze %d : ",stopien-i);
  20. scanf("%d",&wspolczynniki[i]);
  21. }
  22.  
  23. puts("Podaj argument: ");
  24. scanf("%d",&argument);
  25.  
  26. printf("W( %d ) = %d",argument,horner(wspolczynniki,stopien,argument));
  27.  
  28. getchar();
  29. return 0;
  30. }
  31.  
  32. int horner(int wsp[],int st, int x)
  33. {
  34. if(st==0)
  35. return wsp[0];
  36.  
  37. return x*horner(wsp,st-1,x)+wsp[st];
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement