I'm trying to write a code that asks from the user to give 5 coefficients for a 5th-degree polynomial, and it also asks to give a range (two values) that the programs checks if there is a solution in it or not (I'm asked to find only one), and the solution must be an integer, while the coefficients can be floats.
I'm thinking of writing a code that runs over every integer in the range and substitute it in a description of a polynomial than I define, and check if its equal to zero, but I got stuck at deciding how to make the loops.
And another thing, if there are more than one root in the interval that the user enters, then we must print the minimal value of the roots (but I have no direction how to do that either).
I will show you what I wrote so far, and any kind of help would be appreciated:
#include <stdio.h>
#define zero 0.00001
int main()
{
double a, b, c , d , e , f , y , beginning_of_range, end_of_range;
int x;
printf("please enter the coefficients of the polynomial:\n");
scanf("%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e);
printf("please enter two values to indicate the beginning and end of range:\n");
scanf("%lf%lf", &beginning_of_range, &end_of_range);
while (beginning_of_range > end_of_range)
{
printf("ERROR: the range you have entered isn't valid, please try again:");
scanf("%lf%lf", &beginning_of_range, &end_of_range);
}
while (beginning_of_range < end_of_range)
{
x = beginning_of_range;
y = a + b*x + c*x*x + d*x*x*x + e*x*x*x*x + f*x*x*x*x*x;
if (y == zero)
{
printf("the root is:%d", x);
}
else
{
x = x+1;
}
break;
}
return 0;
}