Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- printf("Please enter the coefficients of the polynomial:\n");
- double a0,a1,a2,a3,a4,a5;
- scanf("%lf%lf%lf%lf%lf%lf", &a0,&a1,&a2,&a3,&a4,&a5);
- printf("Please enter the range:\n");
- double start,end =0;
- int checkresults = scanf("%lf%lf", &start,&end);
- while(checkresults != 2 || start > end)
- {
- printf("Invalid range! Please enter the range:\n");
- checkresults =scanf("%lf%lf", &start,&end);
- }
- int newstart = (int)start; int newend = (int)end;
- for (int i=newstart; i<=newend;i++)
- {
- double sum = a0 + a1*i + a2*i*i + a3*i*i*i + a4*i*i*i*i + a5*i*i*i*i*i;
- if( sum >= -0.00001 && sum <= 0.00001)
- {
- printf("The polynomial has a root: x=%d.", i);
- return 0;
- }
- }
- printf("Could not find a root.");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement