#define _CRT_SECURE_NO_WARNINGS //用的vs,使用scanf时需要 #include #include //使用sqrt函数需导入 //求方程式ax^2+bx+c=0的根 int main() { float a, b, c, d, x1, x2; scanf("%f %f %f", &a, &b, &c);//赋初值 d = b * b - 4 * a * c;//判别式 x1 = (-b + sqrt(d)) / (2 * a); x2 = (-b - sqrt(d)) / (2 * a); if (d > 0) { printf("方程有两个不同的实根%f,%f", x1, x2); } else if (d == 0) { printf("方程有两个相同的实根%f", x1);
} else printf("方程没有实根"); } |