一元二次方程

 1 #include <iostream>
 2 #include <cmath>
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6     float a,b,c,disc;
 7     cout<<"please input a,b,c:";
 8     cin >>a>>b>>c;
 9     if(a==0)
10     cerr<<"a is equal to zero,error!"<<endl;
11     else
12     if((disc=b*b-4*a*c)<0)
13     cerr<<"disc=b*b-4*a*c<0"<<endl;
14     else
15     {
16         cout<<"x1="<<(-b+sqrt(disc))/(2*a)<<endl;
17         cout<<"x2="<<(-b-sqrt(disc))/(2*a)<<endl;
18     }
19     return 0;
20 }
原文地址:https://www.cnblogs.com/borter/p/9405511.html