#include<math.h>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int a,b,c,D;
while(cin >> a,cin >> b,cin >> c)
{
D=b*b-4*a*c;
if(D>0)
{
cout<<"Two different roots x1="<<((-b)+sqrt(D))/(2*a)<<",x2="<<((-b)-sqrt(D))/(2*a);
}
else if(D==0)
{
cout<<"Two same roots x="<<((-b)+sqrt(D))/(2*a);
}
else
{
cout<<"No real root";
}
}
return 0;
}
輸出後變這樣
您的答案為: Two different roots x1=3,x2=2
正確答案為: Two different roots x1=3 , x2=2
幫我解惑一下
#include
#include
#include
using namespace std;
int main()
{
int a,b,c,D;
while(cin >> a,cin >> b,cin >> c)
{
D=b*b-4*a*c;
if(D>0)
{
cout<<"Two different roots x1="<<((-b)+sqrt(D))/(2*a)<<",x2="<<((-b)-sqrt(D))/(2*a);
}
else if(D==0)
{
cout<<"Two same roots x="<<((-b)+sqrt(D))/(2*a);
}
else
{
cout<<"No real root";
}
}
return 0;
}
輸出後變這樣
您的答案為: Two different roots x1=3,x2=2
正確答案為: Two different roots x1=3 , x2=2
幫我解惑一下
很明顯是輸出格式出了錯
輸出時多加個空格吧