• Предмет: Информатика
  • Автор: vladulizko
  • Вопрос задан 5 месяцев назад

С++
напишіть програму, яка виконує задачу: дійсні змінні a, b, c задають коефіцієнти рівняння ax2+bx+c = 0. Написати умову того, що воно:
а) має рівно два дійсні корені;
б) має єдиний дійсний корінь;
в) не має жодного розв'язку;
г) має нескінченно багато розв'язків.
Запитати коефіцієнти, перевірити умову, вивести рівняння з введеними коефіцієнтами та повідомлення щодо кількості коренів рівняння.

Ответы

Ответ дал: nurtv12345678
1

Ответ:

Here is a C++ program that performs the task you described:

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

// Declare variables

double a, b, c;

// Ask for coefficients

cout << "Enter coefficients a, b, and c: ";

cin >> a >> b >> c;

// Check condition

if (a == 0) // a is 0

{

if (b == 0) // b is also 0

{

if (c == 0) // c is also 0

{

cout << "The equation " << a << "x^2 + " << b << "x + " << c << " = 0 has infinitely many solutions." << endl;

cout << "The equation has an infinite number of roots." << endl;

}

else // c is not 0

{

cout << "The equation " << a << "x^2 + " << b << "x + " << c << " = 0 has no solution." << endl;

cout << "The equation has 0 roots." << endl;

}

}

else // b is not 0

{

cout << "The equation " << a << "x^2 + " << b << "x + " << c << " = 0 has a single valid root." << endl;

cout << "The equation has 1 root." << endl;

}

}

else // a is not 0

{

double discriminant = bb - 4a*c;

if (discriminant > 0) // discriminant is positive

{

cout << "The equation " << a << "x^2 + " << b << "x + " << c << " = 0 has exactly two real roots." << endl;

cout << "The equation has 2 roots." << endl;

}

else if (discriminant == 0) // discriminant is 0

{

cout << "The equation " << a << "x^2 + " << b << "x + " << c << " = 0 has a single valid root." << endl;

cout << "The equation has 1 root." << endl;

}

else // discriminant is negative

{

cout << "The equation " << a << "x^2 + " << b << "x + " << c << " = 0 has no solution." << endl;

cout << "The equation has 0 roots." << endl;

}

}

return 0;

}

This program asks the user to enter the coefficients a, b, and c, and then checks the condition to determine the number of roots of the equation. It then outputs the equation with the entered coefficients and the number of roots.

Вас заинтересует