A second order polynomial equation of type $ax^{2} + bx + c = 0$, where $x$ is a variable and $a ne 0$ is known as a Quadratic Equation.
Here, we will be writing a C program to find the roots of a quadratic equation $ax^{2} + bx + c = 0$.
By the Fundamental Theorem of Algebra, a quadratic equation has two roots. These roots are given by
Write a Python program to find Roots of a Quadratic Equation with an example. The mathematical representation of a Quadratic Equation is ax²+bx+c = 0. A Quadratic Equation can have two roots, and they depend entirely upon the discriminant. C Programming Operators. C if.else Statement. The standard form of a quadratic equation is: ax 2 + bx + c = 0, where a, b and c are real numbers and a!= 0. The term b 2 -4ac is known as the discriminant of a quadratic equation. It tells the nature of the roots. To understand this example to Find Quadratic Equation Roots, you should have the knowledge of following C programming topics: C if, ifelse and Nested ifelse For a quadratic equation ax 2 +bx+c = 0 (where a, b and c are coefficients), its roots are given by following the formula. Apr 13, 2016 Write a C program to find all roots of a quadratic equation using if else. Logic to find roots of quadratic equation in C programming. Learn C programming, Data Structures tutorials, exercises, examples, programs, hacks, tips and tricks online.
$x = frac{-b pm sqrt{b^{2} - 4ac}}{2a}$
This is also known as the Quadratic Formula.
The expression $b^{2} - 4ac$ is known as the discriminant of the quadratic equation. The nature of the roots depend heavily on it. From the quadratic formula, we can make out that if
- $b^{2} - 4ac > 0$, the roots are real and unequal
- $b^{2} - 4ac = 0$, the roots are real and equal
- $b^{2} - 4ac < 0$, the roots are imaginary
In the below C program, the roots are computed inside the
if
, else if
and else
blocks, each depending on whether the discriminant is $gt 0$, $= 0$ and $lt 0$. The else
part of the loop computes the real and imaginary parts of the roots separately. Since the discriminant is $lt 0$ (negative), the minus sign is prepended to it to make it positive; for if not, the sqrt()
function will return nan
('Not a Number'). The variables x1
and x2
are assigned the computed values of the roots based on the quadratic formula. The
<math.h>
library is imported to make use of the pow()
and sqrt()
functions. We take a quadratic equation straight out of the classic Hall & Knight's text Elementary Algebra1, which is as follows:
![Equation Equation](https://image.slidesharecdn.com/cprogramcode-141029235950-conversion-gate01/95/c-programming-26-638.jpg?cb=1414627277)
What is archtics ticketing system login. 5x^2 - 15x + 11 = 0
On deducing, the roots are found to be $frac{15 + sqrt{5}}{10}$ and <$frac{15 - sqrt{5}}{10}$ respectively. Kubota k 008 e manual. Substituting for $sqrt{5} approx 2.236$, we get the approximate values of the roots as $1.7236$ and $1.2764$.
How To Do Quadratic Equations
![Table Table](https://www.codingalpha.com/wp-content/uploads/2016/05/Java-Program-To-Find-Roots-of-Quadratic-Equation-e1469361421603.png)
Running our program for the above equation, we get:
Notes
Find Quadratic Equation From Graph
- 1. H. S. Hall & S. R. Knight, Elementary Algebra. London: Macmillan & Co., Ltd., 1896. Chapter XXVI: Quadratic Equations, p. 241, Ex. 1.