酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

3 秒内用 C 语言求解一元二次方程根,附代码示例!

以下是一个使用 C 语言解决此问题的示例代码,并且运行时间通常在 3 秒内: ```c #include <stdio.h> #include <math.h> int main() { double a, b, c; scanf("%lf %lf %lf", &a, &b, &c); double discriminant = b * b - 4 * a * c; if (discriminant > 0) { double root1 = (-b + sqrt(discriminant)) / (2 * a); double root2 = (-b - sqrt(discriminant)) / (2 * a); printf("%.6lf %.6lf\n", root1, root2); } else if (discriminant == 0) { double root = -b / (2 * a); printf("%.6lf\n", root); } else { printf("no\n"); } return 0; } ``` 在这个程序中,首先计算判别式`discriminant`,然后根据判别式的值来确定方程根的情况并输出相应的结果。 ######[AI写代码神器 | 258点数解答 | 2024-09-26 00:24:58]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]