#28407: 為什麼錯啊


rayjerrychen@gmail.com (JerryChen)


#include<iostream>

#include<math.h>

using namespace std;

    int a,b,c,ans1,ans2;

    cin >> a >> b >> c;

    if((b*b)-(4*a*c>0)){

        int x = -b,y = sqrt((b*b)-(4*a*c);

        cout<<"Two different roots x1="<<(x+y)/(2*a)<<", x2="<<((x-y)/(2*a)<<endl;

        }

        else if ((b*b)-(4*a*c==0)){

        ans1 = (-b/(2*a));

        cout<<"Two same roots"<<ans1<<endl;

        }

        else{

            cout<<"No real root"<<endl;

            return 0;

        }

    

 

#28408: Re:為什麼錯啊


linlincaleb@gmail.com (臨末之頌)


#include

#include

using namespace std;

    int a,b,c,ans1,ans2;

    cin >> a >> b >> c;

    if((b*b)-(4*a*c>0)){

        int x = -b,y = sqrt((b*b)-(4*a*c);

        cout<<"Two different roots x1="<<(x+y)/(2*a)<<", x2="<<((x-y)/(2*a)<<endl;

        }

        else if ((b*b)-(4*a*c==0)){

        ans1 = (-b/(2*a));

        cout<<"Two same roots"<<ans1<<endl;

        }

        else{

            cout<<"No real root"<<endl;

            return 0;

        }

    

 

 if((b*b)-(4*a*c>0))

else if ((b*b)-(4*a*c==0))

檢查括號位置