In this paper, by considering distributed optimal control over a PDE, a gradient based iterative Algorithm is proposed for solving is proposed and analyzed. Galerkin finite element method is used for solving underlying PDE, then the adjoint base technique for derivative computation to implementation of the optimal control issue in preconditioned Newton's conjugate gradient method isused. The interface and connection between quadratic programming extracted from discretizing the problem and Newton's type method, as well as the convergence rate of the algorithm in each iteration is established. Updating control values at discretization points in each iteration yields optimal control of the problem, where the corresponding state values at these points approximate the desired function. Numerical experiments are presented for illustrating the theoretical results.