Represent number N (N>1) as N = x + y, where x * y is the maximum possible value
$$\frac{\text{d}}{\text{d}x} x(N-x) = N - 2x$$
At a maximum, \$\frac{\text{d}f}{\text{d}x} = 0\$, so the maximum occurs when \$x = \frac{N}{2}\$. (Left as an exercise: show that it's a maximum and not a minimum).

Therefore you can skip the loop: desiredNumber = N / 2; is all you need. Note that if N is odd this gives the pair \$\left\lfloor \frac{N}{2} \right\rfloor, \left\lceil \frac{N}{2} \right\rceil\$, which is the correct solution in integers.