a006.
一元二次方程式
| From: [114.45.146.230] |
發表日期
:
2015-06-14 19:10
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int a , b ,c , x2, x1;
while(cin>>a){
cin>>b;
cin>>c;
if(pow(b,2)-4*a*c==0){x1=x2=-b/2*a;
cout<<"Two same roots x="<<x1; }
else if(pow(b,2)-4*a*c>0){x1=(-b+sqrt(pow(b,2)-4*a*c))/2*a;
x2=(-b-sqrt(pow(b,2)-4*a*c))/2*a;
cout<<"Two different roots x1="<<x1<<" , x2="<<x2 ;}
else cout<<"No real root";
}
return 0;
}