#21029: 雖然過了但是還是不知道原本的問題在哪裡QQ


h34086115@gs.ncku.edu.tw (H34086115徐圓媛)


//原版

#include <iostream>
#include <cmath>
using namespace std;

int main() {
int a, b, c, x1, x2, x3;
cin >> a >> b >> c;
if (b * b - 4 * a * c > 0) {
x1 = (-b + sqrt(b * b - 4 * a * c)) / 2 * a;
x2 = (-b - sqrt(b * b - 4 * a * c)) / 2 * a;
cout << "Two different roots x1=" << x1 << " , x2=" << x2;
}
else if ((b * b - 4 * a * c) == 0) {
x3 = (-b + sqrt(b * b - 4 * a * c)) / 2 * a;
cout << "Two same roots x=" << x3;
}
else
cout << "No real root";
return 0;
}

#21030: Re:雖然過了但是還是不知道原本的問題在哪裡QQ


anandrewboy70900 (ShowTsai)


 

分母: (2*a)

要加括號