normally homework is not accepted here
but you can easily think it on the lines of loops