1 条题解
-
0
C :
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { double a,b,c,d; scanf("%lf%lf%lf",&a,&b,&c); if(b*b<4*a*c) printf("no real roots"); else if(b*b==4*a*c) printf("%.2f",(-b)/(2*a)); else if(b*b>4*a*c) printf("%.2f\n%.2f",((-b)+sqrt(b*b-4*a*c))/(2*a),((-b)-sqrt(b*b-4*a*c))/(2*a)); return 0; }
C++ :
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double a,b,c; cin>>a>>b>>c; double delt=b*b-4*a*c; double qdel=((-1)*b)/(2*a); double delta=sqrt(delt)/(2*a); if(delt==0) cout<<fixed<<setprecision(2)<<qdel<<endl; else if(delt>0) { cout<<fixed<<setprecision(2)<<qdel+delta<<endl; cout<<fixed<<setprecision(2)<<qdel-delta<<endl; } else { cout<<"no real roots"; } return 0; }
Pascal :
program xx; var a,b,c,d,x,y:real; begin read(a,b,c); d:=b*b-4*a*c; if d>0 then begin x:=(-b+sqrt(d))/2/a; y:=(-b-sqrt(d))/2/a; writeln(x:3:2); writeln(y:3:2); end else if d=0 then writeln('x=y',-b/2/a:3:2) else writeln('no real roots'); end.
- 1
信息
- ID
- 1056
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者