#include <iostream>
#include <cmath> using namespace std; void main() { float a,b,c,d,x1,x2; cin>>a>>b>>c; if(a==0) cout<<"一元二次方程的二次項系數(shù)不得為零\n"; else { d=b*b-4*a*c; if(d<0) { x1=-b/(2*a); x2=sqrt(-d)/(2*a); cout<<"x1="<<x1<<"+"<<x2<<"i"<<endl; cout<<"x2="<<x1<<"-"<<x2<<"i"<<endl; } else { x1=(-b+sqrt(d))/(2*a); x2=(-b-sqrt(d))/(2*a); cout<<x1<<" "<<x2<<endl; } } } |
|