根据輸入的三个系数求ax 2+bx+c=0的根。 实现步骤:在主函数main(中实现以下语句: <注意:本题需要用乎方根网数sart0,所以在main两数前加上 #include “math. h 1、定义整型变量a,b和c,单精度变量d 2、从鍵益輸入三个系数,以空格同隔,存入a、b.c三个変量 中。 3、d赋值为b 2-4ac 8,aer gbxicok根 C滋: 992生貓入时心洞足 4、在屏幕中输出方程的根(保留两位小数):《注意:求d的平方根应写为:sart(d))。
时间: 2023-05-23 07:07:31 浏览: 109
#include <stdio.h>
#include <math.h>
int main() {
double a, b, c, x1, x2;
scanf("%lf %lf %lf", &a, &b, &c);
double delta = b * b - 4 * a * c;
if (delta > 0) {
x1 = (-b + sqrt(delta)) / (2 * a);
x2 = (-b - sqrt(delta)) / (2 * a);
printf("%.2f %.2f", x1, x2);
}
else if (delta == 0) {
x1 = x2 = -b / (2 * a);
printf("%.2f", x1);
}
else {
double realPart = -b / (2 * a);
double imaginaryPart = sqrt(-delta) / (2 * a);
printf("%.2f+%.2fi %.2f-%.2fi", realPart, imaginaryPart, realPart, imaginaryPart);
}
return 0;
}
相关问题
编程求一元二次方程ax2+bx+c=0的根,要求:abc三个参数使用scanf语句输入。
好的,可以使用以下代码实现:
```c
#include <stdio.h>
#include <math.h>
int main()
{
double a, b, c, delta, x1, x2;
printf("请输入一元二次方程ax^2 + bx + c = 0的系数a, b, c:\n");
scanf("%lf%lf%lf", &a, &b, &c);
delta = b * b - 4 * a * c;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2 * a);
x2 = (-b - sqrt(delta)) / (2 * a);
printf("方程的两个实数根分别为:x1 = %lf, x2 = %lf\n", x1, x2);
}
else if (delta == 0)
{
x1 = x2 = -b / (2 * a);
printf("方程的两个相等实数根为:x1 = x2 = %lf\n", x1);
}
else
{
printf("方程无实数根!\n");
}
return 0;
}
```
其中,使用`scanf`函数读入三个参数a、b、c,然后根据判别式delta的大小,分别计算出方程的两个实数根或一个重根,或者无实数根。
作业评分并上传成绩 日· 第2章 3、根据输入的三个系数求aX^2+bX+c=0的根。 实现步骤:在主函数main()中实现以下语句: 2 (注意:本题需要用平方根函数sqrt(),所以在main函数前加上 3 #include “math.h”) ..4 1、定义整型变量a,b和c,单精度变量d 日第3章 2、从键盘输入三个系数,以空格间隔,存入a,b,c三个变量 中。 1 3、d赋值为b^2-4ac 日第9章 b~2-4ac>=0) 3、计算aX^2+bX+c=0的根(注意:第2步输入时应满足 L2 4、在屏幕中输出方程的根(保留两位小数):(注意:求d的平方 根应写为:sqrt(d))。
这道题目要求编写程序,根据输入的三个系数,求解二次方程aX^2+bX+c=0的根,并将作业评分并上传成绩。具体实现步骤是,在主函数main()中编写代码,使用平方根函数sqrt()来计算方程的根。需要注意的是,在main函数前需要加上头文件<math.h>,以便使用sqrt()函数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)