酷代码 AI
菜单
服务商

c语言运行时间3秒内。题目输入一元二次方程的a、b、c ,求该方程的根。 样例: 输入: 1 2 1 输出 -1.000000 -1.000000 输入: 4 5 6 输出 no

以下是一个使用 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`,然后根据判别式的值来确定方程根的情况并输出相应的结果。 [2024-09-26 00:24:58 | AI写代码神器 | 258点数解答]

相关提问
请收藏新域名:pdcd.cn
发财导航,免费问AI
实用工具查看更多
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]
数独游戏 [娱乐类]
经典推箱子 [娱乐类]
AI摸鱼五子棋 [娱乐类]