luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

sao em k thử được trường hợp 2 vậy @@ #835

Closed HuynhDucPhu closed 1 year ago

HuynhDucPhu commented 1 year ago

[#[include

include

include

include

// ax^2 + bx + c = 0 using namespace std; void g1(long double a, long double b, long double k) { // delta long double c = (b b) - 4 a k; long double c1 = sqrt(c); if (c < 0) { cout << "NO"; } else if (c == 0) { long double d = - (b / (2 a)); cout << fixed << setprecision(2) << d; } else if (c > 0) { long double x1 = (-b - c1) / (2 a); long double x2 = (-b + c1) / (2 a); if (x1 >= x2) { cout << fixed << setprecision(2) << x2 << " " << x1; } else { cout << fixed << setprecision(2) << x1 << " " << x2; } } } void g2(long double a, long double b, long double k) { if (b == 0) { // bx + c = 0 if (k == 0) { cout << "INF"; } else { cout << "NO"; } } else { if (b < 0) { cout << fixed << setprecision(2) << - k / b; } else { cout << fixed << setprecision(2) << - k / b; } } } int main() { long double a, b, k; cin >> a >> b >> k; if (a == 0) { g2(a, b, k); } else { g1(a, b, k); } return 0; }](https://pastebin.com/XDURg8Xd)](https://pastebin.com/XDURg8Xd)