  In this paper, by combining modular forms and characteristic forms, we obtain
general anomaly cancellation formulas of any dimension. For $4k+2$ dimensional
manifolds, our results include the gravitational anomaly cancellation formulas
of Alvarez-Gaum\'e and Witten in dimensions 2, 6 and 10 (\cite{AW}) as special
cases. In dimension $4k+1$, we derive anomaly cancellation formulas for index
gerbes. In dimension $4k+3$, we obtain certain results about eta invariants,
which are interesting in spectral geometry.
