#include <bits/stdc++.h>using namespace std;
int main(){int a,b,c;int D,x1,x2;cin>>a>>b>>c;D=(b*b)-(4*a*c);x1=((0-b)+sqrt(D))/2*a;x2=((0-b)-sqrt(D))/2*a;if(D>0)cout<<"Two different roots x1="<<x1<<" , "<<"x2="<<x2<<endl;else if(D==0&&x1==x2)cout<<"Two same roots x="<<x2<<endl;elsecout<<"No real root"<<endl;return 0;}
重根的輸出獨立出來變成(-1*b)/2*a 可以解決這個問題
#include <bits/stdc++.h>using namespace std;
int main(){int a,b,c;int D,x1,x2;cin>>a>>b>>c;D=(b*b)-(4*a*c);x1=((0-b)+sqrt(D))/2*a;x2=((0-b)-sqrt(D))/2*a;if(D>0)cout<<"Two different roots x1="<<x1<<" , "<<"x2="<<x2<<endl;else if(D==0&&x1==x2)cout<<"Two same roots x="<<x2<<endl;elsecout<<"No real root"<<endl;return 0;}
2*a要用括號包起來