WASHINGTON — David H. Petraeus, the director of the Central Intelligence Agency, resigned on Friday after issuing a statement saying that he had engaged in an extramarital affair.