1 条题解
-
0
C :
#include <stdio.h> #include <math.h> void main() { float a,b,c,x1,x2,d; scanf("%f%f%f",&a,&b,&c); d=b*b-4*a*c; if(d<0) printf("No solution\n"); else if(d==0) printf("x1=x2=%.2f\n",-b/(2*a)); else { x1=(-b-sqrt(d))/(2*a); x2=(-b+sqrt(d))/(2*a); printf("x1=%.2f x2=%.2f\n",x1,x2); } }
C++ :
#include<iostream> #include<cmath> #include<cstdio> using namespace std; int main() { float a,b,c,d,x1,x2; while (cin>>a>>b>>c) { d=b*b-4*a*c; if (d>=0) if (d>0) { x1=(-b+sqrt(d))/(2*a); x2=(-b-sqrt(d))/(2*a); if (x2>x1) printf("x1=%.2f x2=%.2f\n",x1,x2); else printf("x1=%.2f x2=%.2f\n",x2,x1); } else { x1=(-b)/(2*a); printf("x1=x2=%.2f\n",x1); } else { cout<<"No solution"<<endl; } } return 0; }
- 1
信息
- ID
- 882
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者