脑子
查看原帖
脑子
1630890
wjf131227楼主2025/1/28 16:27

double a, b, c; cin >> a >> b >> c; double x1, x2; double dlt = b * b - 4 * a * c; dlt = (int)(dlt * 100000) / 100000.0; if (dlt < 0) cout << "No answer!"; if (dlt == 0) { x1=-b/(2a); cout<<"x1=x2="<<fixed<<setprecision(5)<<x1; } if(dlt>0){ x1=(-b+sqrt(dlt))/(2a); x2=(-b-sqrt(dlt))/(2*a); if(x1>x2) swap(x1,x2); cout<<"x1="<<fixed<<setprecision(5)<<x1<<";x2="<<fixed<<setprecision(5)<<x2; } return 0; }

2025/1/28 16:27
加载中...