Quote:
I have tried figuring out the logic but I am having difficulty figure these problems out.
This is HomeWork !
HomeWork must be done by you. Think of it as a mean (for your teacher) to detect your weaknesses and it allow to take remedial actions. Simply giving you a working solution is not help on the long run.
I strongly suggest to report your difficulties to your teacher.
If you are stuck o, code you have already written, please post the code and explain your specific problem.