Let the two numbers be \( x \) and \( y \). We have the following system of equations based on the information given:
- \( xy = 40 \) (the product of the two numbers)
- \( x + y = 13 \) (the sum of the two numbers)
We can express \( y \) in terms of \( x \) using the second equation:
\[ y = 13 - x \]
Now, we can substitute this expression for \( y \) into the first equation:
\[ x(13 - x) = 40 \]
Expanding this, we have:
\[ 13x - x^2 = 40 \]
Rearranging gives us a standard quadratic equation:
\[ x^2 - 13x + 40 = 0 \]
To solve for \( x \), we can use the quadratic formula \( x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \), where \( a = 1, b = -13, c = 40 \):
\[ x = \frac{-(-13) \pm \sqrt{(-13)^2 - 4 \cdot 1 \cdot 40}}{2 \cdot 1} \]
Calculating the discriminant:
\[ (-13)^2 - 4 \cdot 1 \cdot 40 = 169 - 160 = 9 \]
Now substituting back into the formula:
\[ x = \frac{13 \pm \sqrt{9}}{2} = \frac{13 \pm 3}{2} \]
This gives us two possible solutions for \( x \):
- \( x = \frac{16}{2} = 8 \)
- \( x = \frac{10}{2} = 5 \)
From the \( x \) values, we can find the corresponding \( y \) values:
- If \( x = 8 \), then \( y = 13 - 8 = 5 \).
- If \( x = 5 \), then \( y = 13 - 5 = 8 \).
In both cases, the two numbers are \( 8 \) and \( 5 \).
Now, we find their difference:
\[ |x - y| = |8 - 5| = 3 \]
Thus, the difference between the two numbers is \( \boxed{3} \).