Nepal's royalist Prime Minister Surya Bahadur Thapa has announced his resignation on national television and radio, after weeks of street protests.