#28948: 不引用math.h的解法


xxx1752idtc@gmail.com (只有神知道的腦殘)


#include<iostream>

using namespace std;

int main() {

int a,b,c,d[2];

char ch;

while (cin >> a >> b >> c) {

int j = 0;

if (b * b - 4 * a * c < 0) {

cout << "No real root" << endl;

continue;

}

for (int i = (-b - b * b + 4 * a * c) / (2*a);i <= (-b + b * b - 4 * a * c) / (2*a);i++) {

if (a * i * i + b * i + c == 0)

d[j++] = i;

}

if (j == 2)

cout << "Two different roots x1=" << d[1] << " , x2=" << d[0] <<endl;

else

cout << "Two same roots x=" << d[0] << endl;

}

return 0;

}

#28949: Re:不引用math.h的解法


xxx1752idtc@gmail.com (只有神知道的腦殘)


抱歉 這個解法是錯的 請忽視



#28950: Re:不引用math.h的解法


xxx1752idtc@gmail.com (只有神知道的腦殘)


更正 剛剛算過世可以用的 因為本題只有整數解