✔ 最佳答案
nt main()
{
float a;
float b;
float c;
float x1;
float x2;
float one_root;
printf("Please enter value for a:");
scanf("%f", &a);
printf("Please enter value for b:");
scanf("%f", &b);
printf("Please enter value for c:");
scanf("%f", &c);
if (a == 0 && b ==0)
{
printf("There are no solutions.");
}
if (a == 0)
{
one root = -c / b;
printf("There is one root of %f.);
}
if (sqrt(pow (b ,2)) - (4 * a * c)) < 0)
{
printf("There are no real roots.");
}
if (a < 0 && a > 0 && b < 0 && b > 0)
{
x1 = (-b + sqrt ((pow (b, 2)) - (4 * a * c))) / (2 * a);
x2 = (-b + sqrt ((pow (b, 2)) - (4 * a * c))) / (2 * a);
printf("The two real roots are %f and %f.", x1, x2);
}
return 0;
}int main()
{
float <strong class="highlight">a</strong>;
float b;
float <strong class="highlight">c</strong>;
float x1;
float x2;
float one_root;
printf("Please enter value for <strong class="highlight">a</strong>:");
scanf("%f", &a);
printf("Please enter value for b:");
scanf("%f", &b);
printf("Please enter value for <strong class="highlight">c</strong>:");
scanf("%f", &c);
if (<strong class="highlight">a</strong> == 0 && b ==0)
{
printf("There are no solutions.");
}
if (<strong class="highlight">a</strong> == 0)
{
one root = -c / b;
printf("There is one root <strong class="highlight">of</strong> %f.);
}
if (sqrt(pow (b ,2)) - (4 * <strong class="highlight">a</strong> * <strong class="highlight">c</strong>)) < 0)
{
printf("There are no real roots.");
}
if (<strong class="highlight">a</strong> < 0 && <strong class="highlight">a</strong> > 0 && b < 0 && b > 0)
{
x1 = (-b + sqrt ((pow (b, 2)) - (4 * <strong class="highlight">a</strong> * <strong class="highlight">c</strong>))) / (2 * <strong class="highlight">a</strong>);
x2 = (-b + sqrt ((pow (b, 2)) - (4 * <strong class="highlight">a</strong> * <strong class="highlight">c</strong>))) / (2 * <strong class="highlight">a</strong>);
printf("The two real roots are %f and %f.", x1, x2);
}
return 0;
}
上網copy的,睇下得5得