In general, (.*)stationary orbits are simply the altitude where a circular orbit has a period equal to the rotational period of the central body.
In order to find this altitude, we can transform Kepler's third law to solve for R:
Kepler's third law:
$\frac{T^2}{R^3} = \frac{4\pi^2}{G M_{central}}$
Solved for $R$:
$R = \sqrt[3]{\frac{T^2 G M_{central}}{4\pi^2}}$
Using $M_{earth}$ and $T_{earth}$:
$R = \sqrt[3]{\frac{(86164)^2 * (6.67e-11) * (5.97e24)}{4\pi^2}} = \sqrt[3]{\frac{2.97e24}{39.5}} = 4.22e7m = 42,200km$,
where 86164 seconds is the approximate length of Earth's sidereal day (~23h, 56m, 4s).
Subtracting the radius of Earth which is ~6370km, this is an altitude of ~35,800km. This can be confirmed by google.
Using $M_{mars}$ and $T_{mars}$ (which is 40 minutes longer than an Earth day):
$R = \sqrt[3]{\frac{(88643)^2 * (6.67e-11) * (6.39e23)}{4\pi^2}} = \sqrt[3]{\frac{3.36e23}{39.5}} = 2.04e7m = 20,400km$,
where 88643 seconds is the approximate length of a Martian sidereal day (~24h, 37m, 23s).
Subtracting the radius of Mars which is ~3390km, this gives an altitude of about 17,000km.
You can easily look up and substitute the numbers of any celestial body for this!