In this blog post, we learn how to write a C program to find the roots of a quadratic equation?. We will write the C program to find the roots of a quadratic equation using the if-else condition. Write C program to find roots of quadratic equation using switch statements. How to find all roots of a quadratic equation using if else in C programming. Logic to find roots of quadratic equation in C programming.
- C Program To Find Discriminant Of Quadratic Equation
- C Program To Find Roots Of Quadratic Equation Using Pointers
- C++ Quadratic Equation Solver
C program to find roots of a quadratic equation: It calculates the roots of a quadratic equation. Coefficients are assumed to be integers, but roots may or may not be real. For a quadratic equation ax 2 + bx + c = 0 (a≠0), discriminant (b.b-4.a.c) decides the nature of roots. Problem formulation. The quadratic programming problem with n variables and m constraints can be formulated as follows. Given: a real-valued, n-dimensional vector c, an n × n-dimensional real symmetric matrix Q,; an m × n-dimensional real matrix A, and; an m-dimensional real vector b,; the objective of quadratic programming is to find an n-dimensional vector x, that will. A quadratic equation is of the form ax 2 + bx + c = 0 where a ≠ 0. A quadratic equation can be solved by using the quadratic formula. You can also use Excel's Goal Seek feature to solve a quadratic equation. For example, we have the formula y = 3x 2 - 12x + 9.5. It's easy to calculate y for any given x. For x = 1, y = 0.5. In the Quadratic equation in the C program, we will find the roots of the quadratic equations. A quadratic equation is an equation of the second degree, meaning it contains at least one term that is squared. The standard form of the quadratic equation is ax² + bx + c = 0 where a, b and c are real and a!=0, x is an unknown variable.
32 lives keygen. Let see an example,
Quadratic equation:
In algebra, a quadratic equation is an equation that can be rearranged in standard form as,
Below is a direct formula for finding the roots of the quadratic equation.
There are the following important cases of this formula.
Case 1: (Discriminant < 0)
Case 2: (Discriminant 0)
Case 3 (Discriminant > 0):
C Program to Find the Roots of a Quadratic Equation using if-else:
The below program ask the user to enter the value of a,b and c. After getting the value from the user it will calculate on the basis of ‘Discriminant’ value.
Output:
Enter value of a of quadratic equation (aX^2 + bX + c): 2
Enter value of b of quadratic equation (aX^2 + bX + c): 7
Enter values of c of quadratic equation (aX^2 + bX + c): 2
Two distinct and real roots exist: -0.31 and -3.19
Enter value of b of quadratic equation (aX^2 + bX + c): 7
Enter values of c of quadratic equation (aX^2 + bX + c): 2
Two distinct and real roots exist: -0.31 and -3.19
C program to find the roots of a quadratic equation using a function:
Output:
Enter value of ‘a’ of quadratic equation (aX^2 + bX + c): 5
Enter value of ‘b’ of quadratic equation (aX^2 + bX + c): 2
Enter values of ‘c’ of quadratic equation (aX^2 + bX + c): 2
Two distinct complex roots exists: -0.20 + i0.60 and -0.20 – i0.60
Enter value of ‘b’ of quadratic equation (aX^2 + bX + c): 2
Enter values of ‘c’ of quadratic equation (aX^2 + bX + c): 2
Two distinct complex roots exists: -0.20 + i0.60 and -0.20 – i0.60
In this tutorial, we will learn to find the roots or solutions of a quadratic equation in C++. In mathematics, these equations are used in fields such as simplification of expressions, equations of a circle and other conic sections, etc. Here, we will learn a method to find the roots of these equations, and a C++ program that calculates the roots of a given quadratic equation.
Quadratic equation
The general quadratic equation is as follows –
Ax^2 + Bx + C = 0
where,
- A, B, and C are known values.
A is the coefficient of the term containing x^2. Also, A cannot be 0.
B is the coefficient of the term containing x.
C is a constant value. - x is an unknown value or variable
The name ‘quadratic’ means square because the equations contain the square of the unknown variable. The quadratic equations are of degree 2.
For example –
5x^2 + 4x + 1 = 0
x^2 + 2x + 1 = 0
5x^2 + 4x + 1 = 0
x^2 + 2x + 1 = 0
Finding roots of a quadratic equation
Every quadratic equation has exactly two roots. The roots can be equal or distinct, and real or complex. So, to find the nature of roots, calculate the discriminant using the following formula –
Discriminant, D = B^2 – 4AC
- Case 1 – D < 0
If D is less than 0, then the roots and distinct and complex. - Case 2 – D = 0
If D is equal to 0, then the roots are equal and real. - Case 3 – D > 0
If D is greater than 0, then both the roots are real and distinct.
To find both the roots, we use the formula given below –
Root1 = ( -B + square_root(D) ) / 2A
Root2 = ( -B – square_root(D) ) / 2A
Root2 = ( -B – square_root(D) ) / 2A
Program to find roots of a quadratic equation in C++
Now, we will see a program that calculates the roots of a quadratic equation using C++. The program takes the coefficients i.e. A, B, and C from the user and then finds the roots. The C++ program to find roots of the equation is –
C Program To Find Discriminant Of Quadratic Equation
In this program, we find the square root using the in-built sqrt() function of the ‘cmath’ library. The program displays both the roots of the given quadratic equation.
C++ program output
C Program To Find Roots Of Quadratic Equation Using Pointers
The output of the above program is –
The user has entered the value of A, B, and C as 1, 2, and -8 respectively. The roots of the equations always satisfy the equations.
For example –
For example –
C++ Quadratic Equation Solver
So, both the roots satisfy the equation.
Thank you for reading this tutorial. Teri yaadein mulakatein mp3 song by atif aslam. I hope it helps you a lot.