#27976: 想請問各位大大 我用c++寫 測資沒問題 但送出是 NA (score:40%)


didicclc@gmail.com (張聿丞)


#include <iostream>

#include <math.h>

using namespace std;

int main()

{

    int a,b,c,d,x,x1,x2;

    while(cin>>a>>b>>c)

    {

        d = (b*b*2)-(4*a*c);

        if(d>0)

        {

            x1 = (-b+sqrt(d))/(2*a);

            x2 = (-b-sqrt(d))/(2*a);

            cout << "Two different roots x1=" <<x1<<" "<<", x2=" <<x2<<endl;

 

        }

        else if(d==0)

        {

            x = -b/(2*a);

            cout<<"Two same roots x="<<x<<endl;

        }

        else

        {

            cout<<"No real root";

        }

    }

}

謝謝各位大大

#27977: Re:想請問各位大大 我用c++寫 測資沒問題 但送出是 NA (score:40%)


linlincaleb@gmail.com (臨末之頌)


#include

#include

using namespace std;

int main()

{

    int a,b,c,d,x,x1,x2;

    while(cin>>a>>b>>c)

    {

        d = (b*b*2)-(4*a*c);

        if(d>0)

        {

            x1 = (-b+sqrt(d))/(2*a);

            x2 = (-b-sqrt(d))/(2*a);

            cout << "Two different roots x1=" <<x1<<" "<<", x2=" <<x2<<endl;

 

        }

        else if(d==0)

        {

            x = -b/(2*a);

            cout<<"Two same roots x="<<x<<endl;

        }

        else

        {

            cout<<"No real root";

        }

    }

}

謝謝各位大大

d = (b*b*2)-(4*a*c); 改成d = (b*b)-(4*a*c); 看看