原种场的鹏哥


私信TA

用户名:tianpeng1183

访问量:11305

签 名:

一条路走到黑

等  级
排  名 5696
经  验 1449
参赛次数 0
文章发表 25
年  龄 0
在职情况 学生
学  校 南京工程学院
专  业 交通设备与控制工程

  自我简介:

解题思路:





注意事项:一定要细心!





参考代码:

#include <stdio.h>

#include <math.h>

int test1(double a,double b,double c)

{

double t1=-b/2*a, t2=sqrt(b*b-4*a*c)/2*a;

printf("x1=%.3f x2=%.3f\n",t1+t2,t1-t2);

return 0;

}


int test2(double a,double b, double c)

{

double t1=-b/2*a, t2=sqrt(b*b-4*a*c)/2*a;

printf("x1=%.3f x2=%.3f\n",t1+t2,t1-t2);

return 0;

}

int test3(double a,double b,double c)

{

double t1=-b/(2*a), t2=sqrt(4*a*c-b*b)/(2*a);

printf("x1=%.3f+%.3fi x2=%.3f-%.3fi\n",t1,t2,t1,t2);

return 0;

}

int main()

{


double a=4,b=1,c=1;

//scanf("%lf %lf %lf",&a,&b,&c);

double d=b*b-4*a*c;


if(d>0)

{

test1(a,b,c);

}

else if(d==0)

{

test2(a,b,c);

}

else if(d<0)

{

test3(a,b,c);

}


return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区