Vous êtes sur la page 1sur 1

Tutorial 6 1. Calculate the value of the following statement for size of 0.25.

(a) (b) (c) (d) ( ) ( ) ( ) ( )


(

in the range of

with a step

( ) ( )
)

( )

2. Calculate the values of the following statements for in the range of step size of 1 and for in the range of with a step size of 0.5. (a) (b) (c) (d) ( ) ( ) ( ) ( )
(

with a

( ) ( )
) )

( )

3. Write a program using for loop to print out the following sequence exactly, including commas: 2, 4, 6, 8, 10, 12, 14, 16

4. An integer is a prime number if it is divisible only by 1 and itself. For example, 2, 3, 5, 7, and 11 are prime numbers. Write a program that reads an interger and determines if it is a prime munber. If it is not a prime number, print out the smallest division. Otherwise, print out the prime number.Test your program with the numbers -10, 0, 1, 2, 4, 9, 11, and 12. (Hint: Use the modulus operator % to determine if a number is divisable by another number. The smallest divisor of even number is 2. However, you only need to test up to to verify if it is divisable).

Vous aimerez peut-être aussi