Number of Real Solutions for Degree 2

Write a function @numsols2deg(a, b, c)@ that receives as argument the three coefficients of the 2nd degree equation ax2+bx+c=0ax^2 + bx + c = 0 and returns how many real solutions it has: 0, 1, or 2.

The solutions of that equation are given by the expression x=(b±b24ac)/2ax = (-b \pm \sqrt{b^2 - 4ac})/2a (best seen in the pdf version of the statement).

The expression b24acb^2 - 4ac is called its discriminant: if it is negative, then the square root cannot provide real values, and there are no real solutions; if the discriminant is 0, then the square root is also 0 and the two options b±0-b \pm 0 coincide, so that there is a single real solution; if the discriminant is positive, then we obtain two real solutions.

Sample session

Problem information

Author: ProAl

Generation: 2026-01-25T17:14:17.832Z

© Jutge.org, 2006–2026.
https://jutge.org