CSCI 240 - Loops Worksheet 2

for loops

Write for loops to accomplish the scenarios below. Many of the loops are similar. Focus on how they are the same. Note what it was you had to change.

1 a) Add integers from 1 to 10, inclusive. Print the current sum after each addition.

1 b) Add integers from 1 to 50, inclusive. Print the current sum after each addition.

1 c) 1 to 100. ........... 1 to anything.

2) Add integers greater than 1, up to, but not including, 10.

3 a) Print all the multiples of 3, between 1 and 20.

3 b) Print all the multiples of 3, between 100 and 200.

3 c) Print all the multiples of 3, between 2 numbers that are entered by the user.

4) Write a short program to print all the multiples in a given range of an integer entered by the user. The user will also enter the limits.  For example, print the multiples of 3 between 20 and 40: 21, 24, 27, 30, 33, 36, 39..