Series of Exercises N°4
Series of Exercises N°4
Exercise 1 :
Write an algorithm that asks for a starting number and then prints the multiplication table for that
number.
Exercise 2 :
Given a list of N integers, write an algorithm that calculates the sum of positive numbers and the
sum of negative numbers.
Example : If the list is 4, -5, 11, 19, -28, -15.
Exercise 3 :
Q1.1- Solve the exercise using each of the loops: For, While, Repeat.
Q3- Write an algorithm that calculates the sum of the even numbers between (1…N).
Q4- Write an algorithm that calculates the sum: S= 1/2+ 1/4+ 1/6+…
Q5- Write an algorithm that calculates the sum: S= 1/2+ 2/3+ 3/4+…+ N/N+1.
Exercise 4 :
Exercise 5 :
Write an algorithm that reads a positive integer N and displays all its divisors. Then, it
calculates the number of divisors. Finally, it checks if this number is prime or not.
Remark : A prime number is divisible only by 1 or by itself.
Exercise 6 :
Write an algorithm that reads two positive integers A and B and then calculates and
displays their PGCD using the following method:
- If A = B; PGCD(A,B) = A
Exercise 7 :
Write an algorithm that allows for the input of a series of positive integers. The input is
terminated by a negative number, which will not be considered in the calculations. Then,
indefinitely (in a loop), present the user with a menu offering choices to display the
minimum value, the maximum value, the sum, or the average of the entered numbers, or
to exit the program.
Exercise 8 :
Write an algorithm that reads the sequence of prices for a customer's purchases (in
positive integer dinars). The sequence ends with a zero. The algorithm should calculate
the total amount due, read the amount paid, and simulate giving change by displaying the
texts '10 DA', '5 DA', and '1 DA' as many times as there are of each type of denomination
to be returned.
Exercise 9 :
At the birth of a girl, her grandfather opens a bank account for her. Then, on each birthday,
the grandfather deposits 2500 DA into her account, plus an additional amount equal to
three times the girl's age.
Example : When she turns four, he deposits 10030 DA into her account.
Write an algorithm that determines how much the girl will have on her nth birthday.