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

Ответы

Ответ дал: igorShap
0

#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;

}

}

Приложения:
Вас заинтересует