#37780: cpp


a911023@stu.tnssh.tn.edu.tw (207_24_郭孟錡)

學校 : 不指定學校
編號 : 167239
來源 : [140.114.123.111]
最後登入時間 :
2024-04-23 01:01:50
a006. 一元二次方程式 | From: [140.114.196.109] | 發表日期 : 2023-10-07 14:27

#include <iostream>
#include<cmath>
using namespace std;

int main()
{
  int a,b,c,D;
  while(cin >> a >> b  >> c)
    {
      D = b*b-4*a*c;
      if(D>0)
      {
        cout << "Two different roots x1=" << ((-1*b)+sqrt(b*b-4*a*c))/(2*a) << " , x2=" << ((-1*b)-sqrt(b*b-4*a*c))/(2*a);
      }
      else if(D==0)
      {
        cout << "Two same roots x=" << ((-1*b)+sqrt(b*b-4*a*c))/(2*a);
      }
      else
      {
        cout << "No real root" << endl;
      }
    }
  return 0;
}

 
ZeroJudge Forum