The traveling wave formula u(x, t) = f (x - t) + g(x + t) (1) gives the general solution of the wave equation u(tt) = u(xx) on the real line. In particular, from this formula, one can derive the formula for the solution of the wave equation on an interval (by the reflection method) and the d'Alembert formula u(x, t) = u(0)(x - t) + u(0)(x + t)/2 + 1/2 integral(x-t)(x+t) u(1)(s)ds for the solution of the Cauchy problem with the initial conditions u (x, 0) = u(0) (x), u(t)' (x, 0) = u(1) (x). In the present paper, we obtain similar formulas describing wave propagation in a physically inhomogeneous one-dimensional medium (for example, a string with variable density and stiffness); these formulas describe the general (classical) solution of the equation k(x)u(tt) = (k(x)u(x))(x). (2) A formula for the general solution of the Klein-Gordon equation z(tt) = z(xx) - (phi' + phi(2)) z (3) will also be given.