In algebra, **D**iscriminant helps us in deducing 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 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++

`// CPP program to calculate Discriminant ` `#include <bits/stdc++.h> ` ` ` `using` `namespace` `std; ` ` ` `void` `discriminant(` `int` `a, ` `int` `b, ` `int` `c){ ` ` ` ` ` `int` `discriminant = (b*b) - (4*a*c); ` ` ` `if` `(discriminant > 0){ ` ` ` `cout<<` `"Discriminant is "` `<<discriminant ` ` ` `<<` `" which is Positive"` `<<endl; ` ` ` ` ` `cout<<` `"Hence Two Solutions"` `; ` ` ` `} ` ` ` `else` `if` `(discriminant == 0){ ` ` ` `cout<<` `"Discriminant is "` `<<discriminant ` ` ` `<<` `" which is Zero"` `<<endl; ` ` ` ` ` `cout<<` `"Hence One Solution"` `; ` ` ` `} ` ` ` `else` `if` `(discriminant < 0){ ` ` ` `cout<<` `"Discriminant is "` `<<discriminant ` ` ` `<<` `" which is Negative"` `<<endl; ` ` ` ` ` `cout<<` `"Hence No Real Solutions"` `; ` ` ` `} ` `} ` ` ` `// Driver Code ` `int` `main(){ ` ` ` `int` `a = 20, b = 30, c = 10; ` ` ` ` ` `// function call to print discriminant ` ` ` `discriminant(a, b, c); ` ` ` `return` `0; ` `} ` ` ` `// This code is contributed by ` `// Sanjit_Prasad ` |

*chevron_right*

*filter_none*

## Java

`// Java program to calculate discriminant ` `public` `class` `Discriminant{ ` ` ` ` ` `// function to calculate discriminant ` ` ` `static` `int` `disc(` `int` `a, ` `int` `b, ` `int` `c){ ` ` ` `int` `dis = (` `int` `)Math.pow(b,` `2` `) - (` `4` `*a*c); ` ` ` `return` `dis; ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `main(String args[]){ ` ` ` `int` `a=` `20` `; ` ` ` `int` `b=` `30` `; ` ` ` `int` `c=` `10` `; ` ` ` `int` `discriminant = disc(a, b, c); ` ` ` `if` `(discriminant > ` `0` `){ ` ` ` `System.out.println(` `"Discriminant is "` `+ discriminant ` ` ` `+ ` `" which is Positive"` `); ` ` ` `System.out.println(` `"Hence Two Solutions"` `); ` ` ` `} ` ` ` `else` `if` `(discriminant == ` `0` `){ ` ` ` `System.out.println(` `"Discriminant is "` `+ discriminant ` ` ` `+ ` `" which is Zero"` `); ` ` ` `System.out.println(` `"Hence One Solution"` `); ` ` ` `} ` ` ` `else` `{ ` ` ` `System.out.println(` `"Discriminant is "` `+ discriminant ` ` ` `+ ` `" which is Negative"` `); ` ` ` `System.out.println(` `"Hence No Real Solutions"` `); ` ` ` `} ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python program to calculate Discriminant ` ` ` `def` `discriminant(a, b, c): ` ` ` ` ` `discriminant ` `=` `(b` `*` `*` `2` `) ` `-` `(` `4` `*` `a` `*` `c) ` ` ` `if` `discriminant > ` `0` `: ` ` ` ` ` `print` `(` `'Discriminant is'` `, discriminant, ` ` ` `"which is Positive"` `) ` ` ` ` ` `print` `(` `'Hence Two Solutions'` `) ` ` ` ` ` `elif` `discriminant ` `=` `=` `0` `: ` ` ` ` ` `print` `(` `'Discriminant is'` `, discriminant, ` ` ` `"which is Zero"` `) ` ` ` ` ` `print` `(` `'Hence One Solution'` `) ` ` ` ` ` `elif` `discriminant < ` `0` `: ` ` ` ` ` `print` `(` `'Discriminant is'` `, discriminant, ` ` ` `"which is Negative"` `) ` ` ` ` ` `print` `(` `'Hence No Real Solutions'` `) ` ` ` `# Driver Code ` `a ` `=` `20` `b ` `=` `30` `c ` `=` `10` `discriminant(a, b, c) ` |

*chevron_right*

*filter_none*

## C#

`// C# program to calculate ` `// discriminant ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// function to calculate ` `// discriminant ` `static` `int` `disc(` `int` `a, ` ` ` `int` `b, ` `int` `c) ` `{ ` ` ` `int` `dis = (` `int` `)Math.Pow(b, 2) - ` ` ` `(4 * a * c); ` ` ` `return` `dis; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main() ` `{ ` ` ` `int` `a = 20; ` ` ` `int` `b = 30; ` ` ` `int` `c = 10; ` ` ` `int` `discriminant = disc(a, b, c); ` ` ` `if` `(discriminant > 0) ` ` ` `{ ` ` ` `Console.WriteLine(` `"Discriminant is "` `+ ` ` ` `discriminant + ` ` ` `" which is Positive"` `); ` ` ` `Console.WriteLine(` `"Hence Two Solutions"` `); ` ` ` `} ` ` ` ` ` `else` `if` `(discriminant == 0) ` ` ` `{ ` ` ` `Console.WriteLine(` `"Discriminant is "` `+ ` ` ` `discriminant + ` ` ` `" which is Zero"` `); ` ` ` `Console.WriteLine(` `"Hence One Solution"` `); ` ` ` `} ` ` ` ` ` `else` ` ` `{ ` ` ` `Console.WriteLine(` `"Discriminant is "` `+ ` ` ` `discriminant + ` ` ` `" which is Negative"` `); ` ` ` `Console.WriteLine(` `"Hence No Real Solutions"` `); ` ` ` `} ` `} ` `} ` ` ` `// This code is contributed ` `// by anuj_67. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to calculate Discriminant ` ` ` `function` `discriminant(` `$a` `, ` `$b` `, ` `$c` `) ` `{ ` ` ` ` ` `$discriminant` `= (` `$b` `* ` `$b` `) - (4 * ` `$a` `* ` `$c` `); ` ` ` `if` `(` `$discriminant` `> 0) ` ` ` `{ ` ` ` `echo` `"Discriminant is "` `, ` `$discriminant` `, ` ` ` `" which is Positive\n"` `; ` ` ` `echo` `"Henco Two Solutions"` `; ` ` ` `} ` ` ` ` ` `else` `if` `(` `$discriminant` `== 0) ` ` ` `{ ` ` ` `echo` `"Discriminant is "` `, ` `$discriminant` `, ` ` ` `" which is Zero\n"` `; ` ` ` `echo` `"Hence One Solution"` `; ` ` ` `} ` ` ` ` ` `else` `if` `(` `$discriminant` `< 0) ` ` ` `{ ` ` ` `echo` `"Discriminant is "` `, ` `$discriminant` `, ` ` ` `" which is Negative\n"` `; ` ` ` ` ` `echo` `"Hence No Real Solutions"` `; ` ` ` `} ` `} ` ` ` `// Driver code ` `$a` `= 20; ` `$b` `= 30; ` `$c` `= 10; ` ` ` `// function call to print discriminant ` `discriminant(` `$a` `, ` `$b` `, ` `$c` `); ` ` ` `// This code is contributed ` `// by Shashank_Sharma ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Discriminant is 100 which is Positive Hence Two Solutions

This article is contributed by **Chinmoy Lenka**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

## Recommended Posts:

- Program to calculate value of nCr
- Program to calculate age
- Program to calculate the value of sin(x) and cos(x)
- C program to calculate the value of nPr
- Efficient program to calculate e^x
- Calculate Volume of Dodecahedron
- Write a program to calculate pow(x,n)
- Program to calculate the value of nCr Efficiently
- Program to calculate area of Enneagon
- Program to calculate Profit Or Loss
- Calculate area of pentagon with given diagonal
- Program to Calculate the Perimeter of a Decagon
- Program to calculate distance between two points in 3 D
- Program to calculate Root Mean Square
- Program to calculate GST from original and net prices