TP-S2-02-LOOPS
TP-S2-02-LOOPS
Exercise 1
Write a Pascal program that displays the message “Good morning” N times, where N entered by the user.
Exercise 2
Write a Pascal program to calculate the sum S=1+2+3+...+ N, where N entered by the user.
Exercise 3
Write a Pascal program that displays the multiplication table of an integer entered by the user.
Exercise 4
Write a Pascal program that asks for a number between 10 and 20, until the answer matches. In the event of a
response greater than 20, a message will appear: “Smaller!”, and conversely, “Bigger!” » if the number is less
than 10.
Exercise 5
Write a Pascal program implementing the following game:
The first user enters an integer that the second must guess. For this, he has the right to as many attempts as he
wishes. At each failure, the program tells it if the desired integer is larger or smaller than its proposal.
A score indicating the number of moves played is updated and displayed when the integer is found.
Exercise 6
Write a Pascal program that reads in 7 different numbers, then prints out the smallest and the greatest value
and also prints out the position of the smallest value in the input sequence as a number from 1 to 7.
Exercise 7
Write a Pascal program for the problem of determining prime number?
Exercise 8
Write a Pascal program to calculate the value of the expression E,
such that E= (1+2) *(1+2+3) *(1+2+3+4) *…*(1+2+3+…+(N-2) +(N-1) +N), and (N≥2).
Exercise 9
Write a Pascal program to calculate the value of the expression E, with N≥2.
Exercise 10
Write a Pascal program which requires a starting number, and which calculates its factorial. NB: the factorial of
8, noted 8! is worth: 1x2x3x4x5x6x7x8
Exercise 11
Write a Pascal program that allows you to enter N integers and calculate the sum, product and the mean of
even elements and of the odd elements.
...............................................................................................
• The DIV function gives the result of integer division of one number by another. 7 DIV 2 = 3
• The MOD function (read Modulo), allows you to give the remainder of the integer division of one integer by another. 7 MOD 2 = 1
A. GHALI