Test Loops (control test)
1 student:
Loop:
1. Output the numbers from A
up to B
. A
and B
are inputted integers (A < B). Use loop.
Example:
'please, enter two numbers :' 2 6 >>> 2 3 4 5 6
For loop:
2. Output the sequence of numbers : 1 4 7 10 13 16 19 22
. Use FOR loop.
Example:
1 4 7 10 13 16 19 22
3. Calculate a value of the function z (x) = x-2
for all x
varying on the interval [-2, 2]
. Use FOR loop.
Example:
z (-2) = -4 z (-1) = -3 z (0) = -2 z (1) = -1 z (2) = 0
Any loop:
4. Calculate the sum (addition) of the numbers: 2 + 4 + 6 + ... + 20
. Use any loop.
Example:
'the result is:' 110
5. 10 integers are inputted. Find the quantity of positive among the numbers. Use any loop.
Example:
'please, enter 10 numbers:' -2 3 7 2 -6 7 1 9 10 8 >>> 8
6. 10 numbers are entered. Output the maximum number and its serial number (position number). Use any loop.
Example:
'please, enter 10 numbers:' -2 3 7 2 -6 7 1 9 10 8 >>> max = 10 position = 9
While loop:
7. Output the sequence 2 4 8 16 32 64 128 256
. Use WHILE loop.
Example:
'the result is:' 2 4 8 16 32 64 128 256
2 student:
Loop:
1. Output the sequence of numbers : 2 4 6 8 10 12 14
. Use loop.
Example:
2 4 6 8 10 12 14
For loop:
2. Output the numbers from A
down to B
. A
and B
are inputted integers (A > B). Use FOR loop.
Example:
'please, enter two numbers :' 6 2 >>> 6 5 4 3 2
3. Calculate a value of the function z (x) = x*2
for all x
varying on the interval [-3, 2]
. Use FOR loop.
Example:
z (-3) = -6 z (-2) = -4 z (-1) = -2 z (0) = 0 z (1) = 2 z (2) = 4
Any loop:
4. Calculate the product (multiplication) of the numbers: 1 * 3 * 5 * 7 * 9
. Use any loop.
Example:
'the result is:' 945
5. 10 integers are inputted. Find the quantity of even numbers among them. Use any loop.
Example:
'please, enter 10 numbers:' 2 3 7 2 6 7 1 9 10 8 >>> 5
6. 10 numbers are entered. Output the minimum number and its serial number (position number). Use any loop.
Example:
'please, enter 10 numbers:' -2 3 7 2 -6 7 1 9 10 8 >>> min = -6 position = 5
7. Output the sequence 30 25 20 15 10 5 0
. Use WHILE loop.
Example:
'the result is:' 30 25 20 15 10 5 0
While loop:
3 student:
Loop:
1. Output the numbers from A
down to B
. A
and B
are inputted integers (A > B). Use loop.
Example:
'please, enter two numbers :' 6 2 >>> 6 5 4 3 2
For loop:
2. Output the sequence of numbers : 22 19 16 13 10 7 4 1
. Use FOR loop.
Example:
22 19 16 13 10 7 4 1
3. Calculate a value of the function z (x) = x^4
(in a power of 4) for all x
varying on the interval [2, 6]
. Use FOR loop.
Example:
z (2) = 16 z (3) = 81 z (4) = 256 z (5) = 625 z (6) = 1296
Any loop:
4. Calculate the sum (addition) of the numbers: -2 + 0 + 2 + 4 + 6 + ... + 10
. Use any loop.
Example:
'the result is:' 28
5. 10 integers are inputted. Find the quantity of odd numbers among them. Use any loop.
Example:
'please, enter 10 numbers:' 2 3 7 2 6 7 1 9 10 8 >>> 5
6. 10 numbers are entered. Output the maximum and minimum of the entered numbers. Use any loop.
Example:
'please, enter 10 numbers:' -2 3 7 2 -6 7 1 9 10 8 >>> max = 10 min = -6
While loop:
7. Output the sequence 30 28 26 24 22 20
. Use WHILE loop.
Example:
'the result is:' 30 28 26 24 22 20