标签:
1 #include <iomanip> 2 using namespace std; 3 float x1,x2,d,p,q; 4 int main() 5 { 6 void greater(float,float); 7 void equal(float,float); 8 void smaller(float,float); 9 float a,b,c; 10 cin>>a>>b>>c; 11 d=b*b-4*a*c; 12 if(d>0) 13 { 14 greater(a,b); 15 cout<<setiosflags(ios::fixed)<<setprecision(3); 16 cout<<"x1="<<x1<<" "<<"x2="<<x2<<endl; 17 } 18 else if(d==0) 19 { 20 equal(a,b); 21 cout<<setiosflags(ios::fixed)<<setprecision(3); 22 cout<<"x1="<<x1<<" "<<"x2="<<x2<<endl; 23 } 24 else 25 { 26 smaller(a,b); 27 cout<<setiosflags(ios::fixed)<<setprecision(3); 28 cout<<"x1="<<p<<"+"<<q<<"i"<<" "; 29 cout<<"x2="<<p<<"-"<<q<<"i"<<endl; 30 } 31 return 0; 32 } 33 void greater(float a,float b) 34 { 35 x1=(-b+sqrt(d)/(2*a)); 36 x2=(-b-sqrt(d)/(2*a)); 37 } 38 void equal(float a,float b) 39 { 40 x1=x2=(-b)/(2*a); 41 } 42 void smaller(float a,float b) 43 { 44 p=-b/(2*a); 45 q=sqrt(-d)/(2*a); 46 }
标签:
原文地址:http://www.cnblogs.com/wangmengmeng/p/4542583.html