Problem ID :d071. 3.一元二次方程式的根

New Thread

User 過不去

alex0301 SendIMessage
alex

d071. 3.一元二次方程式的根 | From: 211.22.52.6 | Post Date:2020-10-08 12:46:45.0

#include <iostream>
#include <math.h>
using namespace std;
int main () {
    int x,y,z;
    while(cin>>x>>y>>z) {
        double a,b,c;
        a=x;b=y;c=z;
        if((b*b-4*a*c)>0) {
            cout<<"Two different roots x1="<<(-b+sqrt(b*b-4*a*c))/2*a;
            cout<<" x2="<<(-b+sqrt(b*b-4*a*c))/2*a<<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<<"No real root"<<endl;
        }
    }
    return 0;
}
為什麼自己測試多!!
 


文章類型: 一般 | Reply | Back
User Re:過不去

sagit SendIMessage
sagit

d071. 3.一元二次方程式的根 | From: 123.204.123.21 | Post Date:2020-10-09 17:16:35.0

            cout<<"Two different roots x1="<<(-b+sqrt(b*b-4*a*c))/2/a;
其實類似的地方也檢查一下吧
 


文章類型: 一般 | Reply | Back

New Thread

ZeroJudge Forum