8 条题解
-
2lichengjun LV 10 @ 2023-3-26 20:25:11
876AC代码,之前的题解都是错的
//需注意:当b*b-4*a*c<0时,没有答案 #include<iostream> #include<iomanip> #include<stdio.h> #include<math.h> using namespace std; int main(){ double a,b,c,x,y; cin>>a>>b>>c; if(a==0||b*b-4*a*c<0){ cout<<"No answer!"; return 0; } x=(-b+sqrt(b*b-4*a*c))/(2*a); y=(-b-sqrt(b*b-4*a*c))/(2*a); if(fabs(x-y)<1e-6){ printf("x1=x2=%.5lf",x); return 0; } if(x>y)swap(x,y); printf("x1=%.5lf;x2=%.5lf",x,y); return 0; }
-
22022-8-16 11:30:35@
#include <stdio.h> #include <math.h> #include <iostream> using namespace std; int main() { double a,b,c; cin >> a >> b >> c; if (a==0) { cout<<"No answer!"; } else { double x1,x2; x1 = (-b + sqrt(b*b - 4*a*c))/(2*a); x2 = (-b - sqrt(b*b - 4*a*c))/(2*a); if( fabs(x1-x2)< 1e-6) { printf("X1=X2=%.5lf\n",x1); } else { if(x1 > x2) { swap(x1,x2); } printf("x1=%.5lf;x2=%.5lf\n",x1,x2); } } }
-
02024-6-15 20:13:28@
#include<bits/stdc++.h> using namespace std; int main(){ for(long long i=0;i<=514514;i++){ cout<<"1111111111111111111111111111111111111111111111111"; } return 0; }
-
02023-3-26 22:01:02@
#include <stdio.h> #include <math.h> #include <iostream> using namespace std; int main() { double a,b,c; cin >> a >> b >> c; if (a==0) { cout<<"No answer!"; } else { double x1,x2; x1 = (-b + sqrt(b*b - 4*a*c))/(2*a); x2 = (-b - sqrt(b*b - 4*a*c))/(2*a); if( fabs(x1-x2)< 1e-6) { printf("X1=X2=%.5lf\n",x1); } else { if(x1 > x2) { swap(x1,x2); } printf("x1=%.5lf;x2=%.5lf\n",x1,x2); } } }
-
02023-3-10 20:00:03@
真题解
https://jingyan.baidu.com/article/ca00d56c2e0952e99eebcf86.html
不会一元二次的人一定要看
完整代码如下:
#include <stdio.h> #include <math.h> #include <iostream> using namespace std; int main() { double x1,x2; double a,b,c; cin >> a >> b >> c; if ((b * b - 4 * a * c) < 0) { cout<<"No answer!"; } else { if((b * b - 4 * a * c) == 0) { x1 = -1 * (b / (2 * a)); printf("X1=X2=%.5lf\n",x1); } else { x1 = (-b + sqrt(b*b - 4*a*c))/(2*a); x2 = (-b - sqrt(b*b - 4*a*c))/(2*a); if(x1 > x2) { swap(x1,x2); } printf("x1=%.5lf;x2=%.5lf\n",x1,x2); } } }
-
02022-2-9 11:14:53@
#include <iostream> #include <math.h> #include<iomanip> using namespace std; int main() { double x,y,a,b,c; cin>>a>>b>>c; if (a==0) { cout<<"No answer!"; return 0; } x=(sqrt(bb-4ac)-b)/(2a); y=(-sqrt(bb-4ac)-b)/(2a); if (x>y){ swap(x,y); } if (fabs(x-y)<1e-6) { cout<<"x1=x2="<<fixed<<setprecision(5)<<x<<endl; } else { cout<<"x1="<<fixed<<setprecision(5)<<x<<";x2="<<fixed<<setprecision(5)<<y<<endl; } }
-
02022-1-7 10:57:41@
#include <stdio.h> #include <math.h> #include <iostream> using namespace std; int main() { double a,b,c; cin >> a >> b >> c; if (a==0) { cout<<"No answer!"; } else { double x1,x2; x1 = (-b + sqrt(b*b - 4*a*c))/(2*a); x2 = (-b - sqrt(b*b - 4*a*c))/(2*a); if( fabs(x1-x2)< 1e-6) { printf("X1=X2=%.5lf\n",x1); } else { if(x1 > x2) { swap(x1,x2); } printf("x1=%.5lf;x2=%.5lf\n",x1,x2); } } }
-
02022-1-7 10:46:55@
#include <iostream> #include <math.h> #include<iomanip> using namespace std; int main() { double x,y,a,b,c; cin>>a>>b>>c; if (a==0) { cout<<"No answer!"; return 0; } x=(sqrt(b*b-4*a*c)-b)/(2*a); y=(-sqrt(b*b-4*a*c)-b)/(2*a); if (x>y){ swap(x,y); } if (fabs(x-y)<1e-6) { cout<<"x1=x2="<<fixed<<setprecision(5)<<x<<endl; } else { cout<<"x1="<<fixed<<setprecision(5)<<x<<";x2="<<fixed<<setprecision(5)<<y<<endl; } }
- 1
信息
- ID
- 876
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 561
- 已通过
- 137
- 上传者