One of the efficient methods in aerodynamic shape optimization is the adjoint method. This method can be applied in continuous or discrete form. In this research the continuous and discrete adjoint equations have been derived for two dimensional viscous compressible flows. This method has been used to optimize airfoils in subsonic and transonic flows. Each design cycle requires the numerical solution of both the flow and the adjoint equations, leading to a computational cost roughly equal to the cost of flow solver. In this study two approaches for parameterizing the airfoil are utilized. One approach employs the surface mesh points and the other one uses the definition of NACA 4-digit airfoil series. In present work the adjoint method has been used for the two deign problems usually arisen in aerodynamic shape optimization, inverse pressure design and drag minimization with the specified lift constraint. In inverse design problem the optimum value of design variables was obtained successfully. In drag minimization problem the angle of attack was varied to fix the lift coefficient. In presented problems small changes in airfoil geometry have decreased the drag coefficient considerably. For a sample problem the gradients computed using the adjoint approach have been compared to finite difference gradients to examine the correctness of program in gradients calculation