ax^2+bx+c=0 has no solution
ax^2+bx+c=0 has only one solution: y
ax^2+bx+c=0 has two solutions: y and z
ax^2+bx+c=0 has infinite solutions
此問題的直覺想法是, 分開處理可能a==0,b==0,c==0的狀況(想到if了嗎?), 如果a!=0再判斷 b^2-4ac的大小.
除解答需正確外, 凡未對齊(一律內縮四個空格), 或註解不全者一律零分. 你可以使用double sqrt(double x)這個 函數來求平方根, 並以下面的方式來編譯:
gcc -lm yoursource.c -o yourexe以下是範例程式:
/** * Name: root.c * Subject: Calculate the root(s) of ax^2 + bx + c = 0 * Author: Your Name * Begin Date: xx/xx/xxxx * Modified Date: xx/xx/xxxx * Toolkit: gcc */ #include <stdio.h> #include <math.h> int main() { double a, b, c; if (scanf("%lf %lf %lf", &a, &b, &c) != 3) { return 0; } /* fill your code here */ }