The president of the Maldives has resigned, after clashes in the capital, Male, between soldiers and police who sided with anti-government protesters.