精華區beta NTUBIME101HW 關於我們 聯絡資訊
#include <iostream> #include <cmath> using namespace std; int main() { double a,b,c,d; cout << "ax^2+bx+c=0 Please input a,b,c.\na= "; cin >> a; cout << "b= "; cin >> b; cout << "c= "; cin >> c; d = b*b-4*a*c; if(d>0) { cout << "x1= " << (-b+sqrt(d))/(2*a) << endl; cout << "x2= " << (-b-sqrt(d))/(2*a) << endl; } else if(d==0) cout << "x1=x2= " << -b / (2*a) << endl; else { cout << "x1= " << -b/(2*a) << "+" << sqrt((-d))/(2*a) << "i" << endl; cout << "x2= " << -b/(2*a) << "-" << sqrt((-d))/(2*a) << "i" << endl; } system("pause"); return 0; } 明明才多幾行...加一下咩... a = 0的話一定爆喔... 輸入你家的工程計算機a=0他一樣會說math error... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.232.97.219
typenephew:神總是想的比人多 12/08 01:13