#27554: c++


wangsyuan01121@gmail.com (wang syuan)

學校 : 國立交通大學
編號 : 168878
來源 : [42.72.106.132]
最後登入時間 :
2022-07-11 17:33:43
a006. 一元二次方程式 | From: [140.113.230.17] | 發表日期 : 2021-10-13 02:07

 

  int a,b,c,ans1,ans2;

  cin >> a >> b >>c  ;

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

      int x = -b;

      int 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 x="<<ans1<<endl;}

    else

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

  return 0;

}

 
ZeroJudge Forum