Have you got the logic/algorithm for the problem? You will need that before trying to write any code.
What do you get from google?

Here's a link to the for loop tutorial:
The for Statement (The...