Advertisement
Guest User

Yahav Q1

a guest
May 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4.  
  5. int main()
  6. {
  7.  
  8.  
  9. printf("Please enter the coefficients of the polynomial:\n");
  10. double a0,a1,a2,a3,a4,a5;
  11. scanf("%lf%lf%lf%lf%lf%lf", &a0,&a1,&a2,&a3,&a4,&a5);
  12. printf("Please enter the range:\n");
  13. double start,end =0;
  14. int checkresults = scanf("%lf%lf", &start,&end);
  15. while(checkresults != 2 || start > end)
  16. {
  17. printf("Invalid range! Please enter the range:\n");
  18. checkresults =scanf("%lf%lf", &start,&end);
  19. }
  20. int newstart = (int)start; int newend = (int)end;
  21. for (int i=newstart; i<=newend;i++)
  22. {
  23. double sum = a0 + a1*i + a2*i*i + a3*i*i*i + a4*i*i*i*i + a5*i*i*i*i*i;
  24. if( sum >= -0.00001 && sum <= 0.00001)
  25. {
  26. printf("The polynomial has a root: x=%d.", i);
  27. return 0;
  28. }
  29. }
  30. printf("Could not find a root.");
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement