4 solutions
-
5
#include<bits/stdc++.h> using namespace std; int main(){ double a,b,c,x1,x2,n; cin>>a>>b>>c; n=b*b-4*a*c;// if(n>=0) { x1=(-b+sqrt(n))/(2*a); //第一个根 x2=(-b-sqrt(n))/(2*a); //第二个根 if(x1==x2) //两根相等 { cout<<fixed<<setprecision(5)<<"x1=x2="<<x1; } else if(x1<x2) //第一个小 { cout<<fixed<<setprecision(5)<<"x1="<<x1<<";x2="<<x2; } else //第二个小 { cout<<fixed<<setprecision(5)<<"x1="<<x2<<";x2="<<x1; } } else //无解 { cout<<"No answer!"; } return 0; }
-
2
#include<bits/stdc++.h> using namespace std; int main() { double a,b,c,x1/*根1*/,x2/*根2*/,n; cin>>a>>b>>c; n = b*b-4*a*c; if (n>=0)//有解 { x1 = (-b+sqrt(n))/(2*a);//根1 x2 = (-b-sqrt(n))/(2*a);//根2 if (n==0) cout<<fixed<<setprecision(5)<<"x1=x2="<<x1;//根相等 else if (x1<x2) cout<<fixed<<setprecision(5)<<"x1="<<x1<<";x2="<<x2; else cout<<fixed<<setprecision(5)<<"x1="<<x2<<";x2="<<x1; } else cout<<"No answer!";//无解 return 0; }
-
-2
#include<bits/stdc++.h> using namespace std; int main() { double a,b,c,x1,x2; cin>>a>>b>>c; if ((b*b-4*a*c)<0) { cout<<"No,answer!"; } else{ x1 = (-b+sqrt(pow(b,2)-4*a*c))/(2*a); x2 = (-b-sqrt(pow(b,2)-4*a*c))/(2*a); if ((b*b-4*a*c)==0) { cout<<"x1=x2="<<fixed<<setprecision(5)<<x1; } else if((b*b-4*a*c)>0){ if(x1 < x2) { cout<<"x1="<<fixed<<setprecision(5)<<(-b+sqrt(pow(b,2)-4*a*c))/(2*a)<<';'<<"x2="<<(-b-sqrt(pow(b,2)-4*a*c))/(2*a); }else{ cout<<"x1="<<fixed<<setprecision(5)<<(-b-sqrt(pow(b,2)-4*a*c))/(2*a)<<';'<<"x2="<<(-b+sqrt(pow(b,2)-4*a*c))/(2*a); } } } return 0; }
-
-3
#include<bits/stdc++.h> using namespace std; int main(){ double a,b,c,x1,x2,n; cin>>a>>b>>c; n=b*b-4*a*c; if(n>=0) { x1=(-b+sqrt(n))/(2*a); x2=(-b-sqrt(n))/(2*a); if(x1==x2) { cout<<fixed<<setprecision(5)<<"x1=x2="<<x1; } else if(x1<x2) { cout<<fixed<<setprecision(5)<<"x1="<<x1<<";x2="<<x2; } else { cout<<fixed<<setprecision(5)<<"x1="<<x2<<";x2="<<x1; } } else { cout<<"No answer!"; } return 0; }
- 1
Information
- ID
- 865
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- (None)
- # Submissions
- 125
- Accepted
- 31
- Uploaded By