#29542:


e3524167 (Kenlogin)

學校 : 不指定學校
編號 : 186743
來源 : [182.233.207.92]
最後登入時間 :
2022-03-17 21:12:56
a006. 一元二次方程式 | From: [182.233.207.92] | 發表日期 : 2022-03-10 21:16

#include <iostream>

#include <math.h>

using namespace std;

int main()

{

int a, b, c;

int x1 = 0,x2 = 0;

int dis = 0;

 

cin >> a >> b >> c;

dis = b * b - 4 * a * c;

 

if (dis < 0)

{

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

}

else if (dis == 0)

{

x1 = x2 = (-b) / (2 * a);

cout << "Two same roots " << "x=" << x1 << endl;

}

else

{

x1 = (-b + sqrt(dis)) / (2 * a);

x2 = (-b - sqrt(dis)) / (2 * a);

cout << "Two different roots " << "x1=" << x1 << " " << ", " << "x2=" << x2 << endl;

}

}

 
ZeroJudge Forum