解题思路:
注意事项:一定要细心!
参考代码:
#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 人评分
矩形面积交 (Java代码)浏览:1281 |
A+B for Input-Output Practice (V) (C++代码)浏览:485 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:702 |
简单的a+b (C语言代码)浏览:626 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:504 |
老王赛马 (C++代码)浏览:973 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:521 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:648 |
C语言训练-求素数问题 (C语言代码)浏览:630 |
简单的a+b (C语言代码)浏览:536 |