The president and prime minister of the Central African Republic have both resigned after months of violence and sectarian tensions in the country.