• Составьте програму вычисления корней квадратного уравнения. С++

Ответы 1

  • #include <iostream>

    #include <math.h>

    using namespace std;

    int main()

    {

    double a, b, c, x1, x2, d;

     

    do{

     cout << "Input a: ";

     cin >> a;

     if (a == 0) {

      cout << "Error! a = 0! This isn't a square equation! Try again" << endl;

     }

    } while (a == 0);

    cout << "Input b: ";

    cin >> b;

    cout << "Input c: ";

    cin >> c;

     

    d = b * b - 4. * a * c;

     

    if (d < 0) {

     cout << "No roots";

     return 1;

    }  

    else if (d == 0) {

     cout << "x = " << -b / 2. / a;

     return 2;

    }

    else {

     cout << "x1 = " << (-b + sqrt(d)) / 2. / a << ", x2 = " << (-b - sqrt(d)) / 2. / a;

     return 0;

    }

    }

    answer img
  • Добавить свой ответ

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years