#02 – Practice tasks for Basics of Programming 1.
2015.10.06.

#1 WHILE loop

· Write a program that prints out the integer numbers from 3 to 289 – use while loop.

· Write a program that prints out the integer numbers from 3 to 289 that are dividable with 3 – use while loop.

· Write a program that prints out ‘Hello’ on the screen 129 times, one below the other – use while loop.

· Write a program that multiplies 8 with all numbers between 1 and 20 and prints out the results in the format shown below – use while loop:

1 x 8 = 8

2 x 8 = 16

3 x 8 = 24

20 x 8 = 160


#2 FOR loop, SCANF

Already known problems, rewrite your programs to use for loops instead of while:

· Write a program that prints out the integer numbers from 3 to 289 – use for loop.

· Write a program that prints out the integer numbers from 3 to 289 that are dividable with 3 – use for loop.

· Write a program that prints out ‘Hello’ on the screen 129 times, one below the other – use for loop.

· Write a program that multiplies 8 with all numbers between 1 and 20 and prints out the results in the format shown below – use for loop:

1 x 8 = 8

2 x 8 = 16

3 x 8 = 24

20 x 8 = 160


#3 FOR and WHILE, no arrays

New tasks – you may use for or while loops, but you must not use arrays!

· Write a program that multiplies 2 integer numbers. First scan the 2 numbers, then print out the result.

· Write a program that calculates the surface area of a cylinder. First scan the radius and height of the cylinder (two real numbers), then print out the surface area. S = 2r?h+ 2r2p

· Write a program that scans a number, calculates its square, prints it on the screen – and repeats these steps until the user enters 0.

The modulo operator (%) gives you the remainder of a division. For example:

15 % 3 is 0, because 15 is dividable with 3;

14 % 5 is 4, because 14 divided by 5 is 2, and the remainder is 4;

11 % 2 is 1, because 11 divided by 2 is 5, and the remainder is 1.

· Find the first 100 prime numbers and print them on the screen, one below the other. No special algorithm needed, simply check every number starting from two (2) if it can be divided with any other number smaller than that. For example, when checking if 7 is a prime number, you must check if it is dividable with 2, 3, 4, 5, 6. First construct the algorithm on paper, then write the source code.