The Wayback Machine - https://web.archive.org/web/20240118175023/https://www.geeksforgeeks.org/calculate-discriminant-value/
Open In App
Related Articles

Calculate the Discriminant Value

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In algebra, Discriminant helps us deduce various properties of the roots of a polynomial or polynomial function without even computing them. Let’s look at this general quadratic polynomial of degree two: 
 

ax^2+bx+c

Here the discriminant of the equation is calculated using the formula: 
 

b^2-4ac 

Now we can deduce the following properties: 
 

  • If the discriminant is equal to zero then the polynomial has equal roots i.e., a=b.
  • If the discriminant is positive and the coefficients are real, then the polynomial has two real roots.

Here are a few conditions that we must keep in mind while programming and making deductions from the discriminant: 
 

  • If the discriminant is equal to zero then one solution is possible.
  • If the discriminant is positive then two solutions are possible.
  • If the discriminant is negative then no real solutions are possible.

Examples: 
 

Input:
a = 20
b = 30
c = 10
Explanation:
(30**2) - (4*20*10) 
Output:
Discriminant is 100 which is positive
Hence Two solutions

Input:
a = 9
b = 7
c = 12
Explanation:
(30**2) - (4*20*10) 
Output:
Discriminant is -383 which is negative
Hence no real solutions

 

 

C++





Java





Python3





C#





PHP





Javascript





Output: 
 

Discriminant is 100 which is Positive
Hence Two Solutions

Time Complexity: O(1) since constant operations are being performed

Auxiliary Space: O(1), since no extra space has been taken.

 


Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 17 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials