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

C语言实现:输入一元二次方程系数a、b、c求解方程的根

以下是用 C 语言解决此问题的代码: ```c #include <stdio.h> #include <math.h> int main() { double a, b, c; double discriminant, root1, root2; printf("请输入 a、b、c:\n"); scanf("%lf %lf %lf", &a, &b, &c); discriminant = b * b - 4 * a * c; if (discriminant > 0) { root1 = (-b + sqrt(discriminant)) / (2 * a); root2 = (-b - sqrt(discriminant)) / (2 * a); printf("%.6lf %.6lf\n", root1, root2); } else if (discriminant == 0) { root1 = -b / (2 * a); printf("%.6lf\n", root1); } else { printf("no\n"); } return 0; } ``` ######[AI写代码神器 | 237点数解答 | 2024-09-26 00:18:01]

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