0% found this document useful (0 votes)
0 views4 pages

Quadratic Equation CPP Project

This document explains how to solve a quadratic equation using C++ programming, specifically the equation 6x² + 11x - 35 = 0. It details the theory behind quadratic equations, including the discriminant and its implications for the nature of the roots, and provides a complete C++ code example to calculate the roots. The output shows that the equation has two distinct real roots: approximately 1.67 and -3.5.

Uploaded by

abirsaha3173
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

Quadratic Equation CPP Project

This document explains how to solve a quadratic equation using C++ programming, specifically the equation 6x² + 11x - 35 = 0. It details the theory behind quadratic equations, including the discriminant and its implications for the nature of the roots, and provides a complete C++ code example to calculate the roots. The output shows that the equation has two distinct real roots: approximately 1.67 and -3.5.

Uploaded by

abirsaha3173
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Solving a Quadratic

Equation using C++


1. Introduction
A quadratic equation is a second-degree polynomial equation of
the form:
ax² + bx + c = 0,(where a, b, and c are constants and a ≠ 0.)

Solving quadratic equations is fundamental in


mathematics and computer science. In this project, we will solve
the quadratic equation:
6x² + 11x − 35 = 0
using C++ programming.

2. Theory of Quadratic Equations


The standard formula to find the roots of a quadratic equation
is:
x = (-b ± √(b² - 4ac)) / 2a

The discriminant D = b² - 4ac determines the nature of roots:


- If D > 0: Two distinct real roots
- If D = 0: Two equal real roots
- If D < 0: Complex conjugate roots
In our equation:
a = 6, b = 11, c = -35
Discriminant = 11² − 4×6×(-35) = 121 + 840 = 961 (positive)
Thus, it has two distinct real roots.
3. C++ Code Explanation
To solve this, we:
- Accept or define the coefficients a, b, and c
- Compute the discriminant D
- Apply the quadratic formula
- Display the results

We'll use the <cmath> library to calculate the square root.

4. Complete C++ Code


#include <iostream>

#include <cmath> // For sqrt function

using namespace std;

int main() {

double a = 6, b = 11, c = -35;

double discriminant, root1, root2;

// Calculate the discriminant

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

cout << "Given Quadratic Equation: 6x^2 + 11x - 35 = 0\


n";

// Check if discriminant is positive, zero or negative

if (discriminant > 0) {

root1 = (-b + sqrt(discriminant)) / (2 * a);


root2 = (-b - sqrt(discriminant)) / (2 * a);

cout << "Roots are real and different.\n";

cout << "Root 1 = " << root1 << endl;

cout << "Root 2 = " << root2 << endl;

} else if (discriminant == 0) {

root1 = root2 = -b / (2 * a);

cout << "Roots are real and equal.\n";

cout << "Root = " << root1 << endl;

} else {

double realPart = -b / (2 * a);

double imaginaryPart = sqrt(-discriminant) / (2 * a);

cout << "Roots are complex and imaginary.\n";

cout << "Root 1 = " << realPart << " + " <<
imaginaryPart << "i\n";

cout << "Root 2 = " << realPart << " - " <<
imaginaryPart << "i\n";

return 0;}

5. Output
Given Quadratic Equation: 6x² + 11x - 35 = 0
Roots are real and different.
Root 1 = 1.66667
Root 2 = -3.5
So, the roots of the equation 6x² + 11x − 35 = 0 are:
- x = 5/3 (≈1.67)
- x = -3.5

6. Conclusion
This project demonstrates how quadratic equations can
be solved easily with C++. By using the discriminant
and the quadratic formula, we computed the exact
roots. This approach can be extended to handle any
type of quadratic equation efficiently.

You might also like