所以我正在尝试制作一个求解二次方程的 C 程序。我首先从头开始编写它,但它显示了相同的错误,所以我从一本 C 编程书籍中对其进行了一些更改。结果如下:
/*
Solves any quadratic formula.
*/
#include <stdio.h>
#include <math.h>
void main()
{
float a, b, c, rt1= 0, rt2=0, discrim;
clrscr();
printf("Welcome to the Quadratic Equation Solver!");
getch();
printf("\nYour quadratic formula should be of the form a(x*x)+bx+c = 0");
printf("\nPlease enter a\'s value:");
scanf("%f", &a);
printf("Great! Now enter b\'s value:");
scanf("%f", &b);
printf("One more to go! Enter c\'s value:");
scanf("%f", &c);
discrim = b*b - 4*a*c;
if (discrim < 0)
printf("\nThe roots are imaginary.");
else
{
rt1 = (-b + sqrt(discrim)/(2.0*a);
rt2 = (-b - sqrt(discrim)/(2.0*a);
printf("\nThe roots have been calculated.");
getch();
printf("\nThe roots are:\nRoot 1:%f\nRoot 2:%f",rt1, rt2);
getch();
printf("\nThank you!");
getch();
}
}