先說聲抱歉
我是個C++新手
什麼都不太懂
這是我寫的程式碼
不知道有哪裡需要修改
才會符合系統規定呢?
#include <iostream>
#include <math.h>
using namespace std;
int main () {
double a;
double b;
double c;
cout << "輸入三個整數 a, b, c\n" ;
cout << "a=";
cin >> a;
cout << "b=";
cin >> b;
cout << "c=";
cin >> c;
cout << "\n";
if (pow(b,2)-4*a*c<0)
cout << "No real root";
else if (pow(b,2)-4*a*c==0)
cout << "Two same roots x=" << (-b+pow((pow(b,2)-4*a*c),0.5)/2) ;
else
cout << "Two different roots x1=" <<(-b+pow((pow(b,2)-4*a*c),0.5)/2) << " , x2=" <<(-b-pow((pow(b,2)-4*a*c),0.5)/2) ;
return 0 ;
}
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a, b, c;
while(cin >> a >> b >> c)
{
if(b*b-4*a*c<0)
cout << "No real root"<<endl;
else if(b*b-4*a*c==0)
cout << "Two same roots x="<<(-b+sqrt(b*b-4*a*c))/2*a<<endl;
else
cout << "Two different roots x1="<<(-b+sqrt(b*b-4*a*c))/2*a<< " , x2="<<((-b)-sqrt(b*b-4*a*c))/2*a<<endl;
}
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a, b, c;
while(cin >> a >> b >> c)
{
if(b*b-4*a*c<0)
cout << "No real root"<<endl;
else if(b*b-4*a*c==0)
cout << "Two same roots x="<<(-b+sqrt(b*b-4*a*c))/2*a<<endl;
else
cout << "Two different roots x1="<<(-b+sqrt(b*b-4*a*c))/2*a<< " , x2="<<((-b)-sqrt(b*b-4*a*c))/2*a<<endl;
}
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a, b, c;
while(cin >> a >> b >> c)
{
if(b*b-4*a*c<0)
cout << "No real root"<<endl;
else if(b*b-4*a*c==0)
cout << "Two same roots x="<<(-b+sqrt(b*b-4*a*c))/2*a<<endl;
else
cout << "Two different roots x1="<<(-b+sqrt(b*b-4*a*c))/2*a<< " , x2="<<((-b)-sqrt(b*b-4*a*c))/2*a<<endl;
}
return 0;
}