⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program_5_1.cpp

📁 c++程序设计讲义 cppprograming 含源码
💻 CPP
字号:
// Program 5.1: Determines roots of a quadratic equation
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    cout << "Coefficients for quadratic equation: ";
    double a;
    double b;
    double c;
    cin >> a >> b >> c;
    if ((a != 0) && ((b*b - 4*a*c) > 0)) {
        double radical = sqrt(b*b - 4*a*c);
        double root1 = (-b + radical) / (2*a);
        double root2 = (-b - radical) / (2*a);
        cout << "The roots of " << a << "x^2 + " << b
          << "x + " << c << " are:" << endl << root1 << " and "
          << root2 << endl;
    }
    else {
        cout << a << "x^2 + " << b << "x + " << c
          << " does not have two real roots" << endl;
    }
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -