A new numerical method for a class of Volterra and Fredholm integral equations