- 题解
为啥错了 T1058
- 2023-11-4 16:03:53 @
# include <bits/stdc++.h>
using namespace std;
int main ()
{
double a,b,c;
cin>>a>>b>>c;
if(sqrt(b*b-4*a*c)>0)
{if((-b+sqrt(b*b-4*a*c))/(2*a)<(-b-sqrt(b*b-4*a*c))/(2*a))
printf("x1=%.5lf;x2=%.5lf",(-b+sqrt(b*b-4*a*c))/(2*a),(-b-sqrt(b*b-4*a*c))/(2*a));}
if(sqrt(b*b-4*a*c)<0)
cout<<"No answer!";
if(sqrt(b*b-4*a*c)==0)
printf("x1=x2=%.5lf",(-b+sqrt(b*b-4*a*c))/(2*a));
return 0;
}
7 comments
-
changmengyu LV 6 @ 2024-1-28 15:42:02
@UID:2 sfasfasdfads
-
2024-1-28 15:39:14@
@2 dfasdf
-
2024-1-28 15:38:48@
@34 fdsv
-
2024-1-28 15:36:50@
@47 的撒
-
2024-1-28 15:36:09@
@34 的撒旦
-
2024-1-28 15:31:01@
-
2023-11-5 11:52:21@
1.判别式()是 不能带根号。根号下不能是负数。
2.时输出就行了。# include <bits/stdc++.h> using namespace std; int main () { double a,b,c; cin>>a>>b>>c; if(b*b-4*a*c>0) if((-b+sqrt(b*b-4*a*c))/(2*a) > (-b-sqrt(b*b-4*a*c))/(2*a)) printf("x1=%.5lf;x2=%.5lf",(-b-sqrt(b*b-4*a*c))/(2*a),(-b+sqrt(b*b-4*a*c))/(2*a)); else printf("x1=%.5lf;x2=%.5lf",(-b+sqrt(b*b-4*a*c))/(2*a),(-b-sqrt(b*b-4*a*c))/(2*a)); if(b*b-4*a*c<0) cout<<"No answer!"; if(b*b-4*a*c == 0) printf("x1=x2=%.5lf",(-b)/(2*a)); return 0; }
- 1