精華區beta NTUCH-HW 關於我們 聯絡資訊
功能 用到的觀念 CODE #include<iostream>//header file #include<iomanip> #include<cmath> using namespace std; using std::setw; using std::fixed; using std::setprecision; #include<string> using std::string; using std::getline; int hcf(int, int); int main() { double a,b,c,d,m1,m2; 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+sqrt(d))/2*a<<endl; } else if (d<0) { 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; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.7.59