#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if((b*b)-(4*a*c)>0)
{
float n=sqrt((b*b)-(4*a*c));
int x1=(-b+n)/(2*a),x2=(-b-n)/(2*a);
cout<<"Two different roots x1="<<x1<<",x2="<<x2<<endl;
}
else if((b*b)-(4*a*c)==0)
{
int x=-b/(2*a);
cout<<"Two same roots x="<<x<<endl;
}
else if((b*b)-(4*a*c)<0)
{
cout<<"No real root";
}
return 0;
}
#include
#include
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if((b*b)-(4*a*c)>0)
{
float n=sqrt((b*b)-(4*a*c));
int x1=(-b+n)/(2*a),x2=(-b-n)/(2*a);
cout<<"Two different roots x1="<<x1<<",x2="<<x2<<endl;
}
else if((b*b)-(4*a*c)==0)
{
int x=-b/(2*a);
cout<<"Two same roots x="<<x<<endl;
}
else if((b*b)-(4*a*c)<0)
{
cout<<"No real root";
}
return 0;
}
最後變這樣
您的答案為: Two different roots x1=2,x2=-5 正確答案為: Two different roots x1=2 , x2=-5
#include
#include
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if((b*b)-(4*a*c)>0)
{
float n=sqrt((b*b)-(4*a*c));
int x1=(-b+n)/(2*a),x2=(-b-n)/(2*a);
cout<<"Two different roots x1="<<x1<<",x2="<<x2<<endl;
}
else if((b*b)-(4*a*c)==0)
{
int x=-b/(2*a);
cout<<"Two same roots x="<<x<<endl;
}
else if((b*b)-(4*a*c)<0)
{
cout<<"No real root";
}
return 0;
}
???多輸出兩個空格不就好了?