代码如下:
#include<iostream>
#include<cmath>
using namespace std;
int main(){
cout<<"请输入a,b,c:";
int a,b,c,dat;
cin>>a>>b>>c;
dat=pow(b,2)-4*a*c;
if(dat<0){
cout<<"该方程没有实数根";
}else if(dat==0){
cout<<"该方程的实数根是:"<<(b-2*b+sqrt(dat))/4*a;
}else{
cout<<"该方程的实数根是:"<<"x1="<<((b-2*b+sqrt(dat))/4*a)*2<<endl;
cout<<"x2="<<((b+sqrt(dat))/4*a)*2;
}
return 0;
}