- C++ Program To Find Roots Of Quadratic Equation
- C Program To Find Roots Of Quadratic Equation Using Pointers
- C Program To Get Quadratic Equation
- C Program To Solve Quadratic Equation
- C Program To Find Quadratic Equation Using Switch Case
Overview
In this tutorial, we will write a simple C++ Program to Find Quadratic Equation Roots. The roots for the equation can be calculated as shown below:
Root 1 =
Root 2=
Program to find the roots of Quadratic Equation. Here we will discuss how to find the roots of quadratic equation where it is given that real roots exists for the given equation, using C programming language. Quadratic Equation is equation of the form ax 2 + bx + c = 0, where a, b and c are real numbers and a!= 0. The term b 2-4ac is known.
C++ Program
- Enter quadratic equation in the format ax^2+bx+c: 2x^2+4x+-1 Roots of quadratic equation are: 0.000, -2.000 Other Related Programs in c C Program to calculate the Combinations and Permutations.
- Next: Write a C# Sharp program to read roll no, name and marks of three subjects. Within this program to find roots of quadratic equation example, User entered Values are 10 15 -25. It means a = 10, b = 15, c = -25 and the Quadratic equation is 10x²+15x-25 = 0.
Sample Output
Root 1 := 6 Root 2 := -2 Process returned 0 (0x0) execution time : 2.083 s Press any key to continue.
Enhancements
We can further enhance the program to prompt the input values of a, b, c to the user. Right now we have to modify the code for the values.
Generate the equation string based on the values of a, b, and c and display the equation string in the output.
C++ Program To Find Roots Of Quadratic Equation
Take into consideration the imaginary roots if discriminant is less than 0. The logic is outlined in the flowchart link
Flowchart :
The IDE used in the tutorial is Code:: Blocks. To download and install Code Blocks follow the link:
C Program To Find Roots Of Quadratic Equation Using Pointers
For more information on Code Blocks IDE used in the program , visit the official website of Code blocks IDE: http://www.codeblocks.org/
- Related Questions & Answers
- Selected Reading
We can apply the software development method to solve the linear equation of one variable in C programming language.
Requirement
- The equation should be in the form of ax+b=0
- a and b are inputs, we need to find the value of x
Analysis
Here,
- An input is the a,b values.
- An output is the x value.
Algorithm
Refer an algorithm given below to find solution of linear equation.
Program
C Program To Get Quadratic Equation
Following is the C program to find the solution of linear equation −
C Program To Solve Quadratic Equation
Output
C Program To Find Quadratic Equation Using Switch Case
When the above program is executed, it produces the following result −