C Program To Find Quadratic Equation

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 Conditional Statement: Exercise-11 with Solution. Write a C program to calculate the root of a Quadratic Equation. Pictorial Presentation: Sample Solution. C Program for Quadratic Equation Using if else In this program the compiler asks the user to enter the value of coefficients a,b and c then the program finds the roots of the quadratic equation.

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. Input coefficients of quadratic equation from user. Store it in some variable say a, b and c. Find discriminant of the given equation, using formula discriminant = (b.b) - (4.a.c). Learn - Program to find power of a number.

Here we will a write a program to solve quadratic equation in C++ programming language. Let’s first understand how to solve a quadratic equation:

Let’s take the quadratic equation as:ax²+bx+c=0

How program works:

  • Take the values for a, b and c (double type).
  • if, a = b = 0 then invalid equation
  • if b² -4ac < 0 then the real roots
  • if b² -4ac > 0 , x1= (-b+√(b² -4ac))/2a , x1= (-b -√(b² -4ac))/2a
  • The C++ function for √x is sqrt(x).
  • Include math.h for using the sqrt() function.

Now let’s write the program for the same.

Here is a program to solve Quadratic equation in Python

Program to solve Quadratic equation in C++


OUTPUT:


Please comment for any concern or suggestions for improvements.

Related Posts:

  • 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
2xEquationProgram2 + 5x + 3 = 0 is a quadratic equation where a, b and c are 2, 5 and 3 respectively.

C Program To Get Quadratic Equation

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.
Discriminant(D) valueDescription
D < 0We will get two complex roots.
D = 0We will get two equal roots.
D > 0We will get two real numbers.

C program to find all roots of a quadratic equation

QuadraticProgram Output

C Program To Find Roots Of Quadratic Equation Using Pointers


Related Topics

C Program To Find Quadratic Formula

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