- C Program To Find Quadratic Equation
- C Program To Find Discriminant Of Quadratic Equation
- C Program To Find Quadratic Equation Using Switch Case
- Find Quadratic Equation Given Points
- C Program To Find Root Of Quadratic Equation
- Write a C program to find roots of a quadratic equation.
A quadratic equation is a second order equation having a single variable. Any quadratic equation can be represented as ax2 + bx + c = 0, where a, b and c are constants( a can't be 0) and x is unknown variable.
For Example
2x2 + 5x + 3 = 0 is a quadratic equation where a, b and c are 2, 5 and 3 respectively.To calculate the roots of quadratic equation we can use below formula. There are two solutions of a quadratic equation.I have given here a C# program to solve any Quadratic Equation. Quadratic equation is a second order of polynomial equation in a single variable. X = -b +/- sqrt(b^2 - 4ac) / 2a We have to find the value of (b.b - 4.a.c). When it is greater than Zero, we will get two Real Solutions. When it is equal to zero, we will get one Real Solution. 2x 2 + 5x + 3 = 0 is a quadratic equation where a, b and c are 2, 5 and 3 respectively. To calculate the roots of quadratic equation we can use below formula. There are two solutions of a quadratic equation. X = (-2a + sqrt(D))/2 x = (-2a - sqrt(D))/2 where, D is Discriminant, which differentiate the nature of the roots of quadratic equation.
x = (-2a + sqrt(D))/2 x = (-2a - sqrt(D))/2
where, D is Discriminant, which differentiate the nature of the roots of quadratic equation.
Discriminant(D) value | Description |
---|---|
D < 0 | We will get two complex roots. |
D = 0 | We will get two equal roots. |
D > 0 | We will get two real numbers. |
C program to find all roots of a quadratic equation
Program OutputRelated Topics
C Program to calculate factorial of a number |
C program to check year is leap year or not |
C program to check whether a number is prime or not |
C program to find sum of digits of a number using recursion |
C program to find sum of all even numbers between 1 to N |
C program to find perfect numbers between 1 to N using for loop |
C program to find perfect numbers between 1 to N using for loop |
C program to calculate power of a number |
C Program to find nPr and nCr |
List of all C programs |
Before going to the program first let us understand what is a Quadratic Equation?
Quadratic Equation:
A Quadratic Equation is any equation having the form:
where x represents an unknown, and a, b, and c represent known numbers such that a is not equal to 0. If a = 0, then the equation is linear equation, not quadratic.
For Example,
For more understanding you can check out the following link:
C Program To Find Quadratic Equation
Program code to find roots of Quadratic Equation:
Step by Step working of the above Program Code:
![Program Program](https://www.tutorialgateway.org/wp-content/uploads/C-Program-to-Find-Largest-of-Two-Numbers-1.png)
![Find Find](https://i.ytimg.com/vi/NmRPJUiizpg/maxresdefault.jpg)
- First the computer reads the coefficients a , b and c from the user.
- Then it computes the value of determinant using the formula.
determinant=b*b-4*a*c;
- Then checks the determinant value is greater than , equal or less than to zero using if else if ladder.
- If the determinant value is greater than zero, then root1 and root2 value is calculated using the formula:
r1=(-b+sqrt(determinant))/(2*a)
r2=(-b-sqrt(determinant))/(2*a)
- If the determinant value is equal to zero, then root1 and root2 value is calculated using the formula:
r1=r2=-b/(2*a)
- If the determinant value is less than zero, then root1 and root2 value is calculated using the formula:
C Program To Find Discriminant Of Quadratic Equation
real=-b/(2*a)
imag=sqrt(-determinant)/(2*a)
C Program To Find Quadratic Equation Using Switch Case
- Finally print the roots of the quadratic equation.