PW 2: Discovering The Environment 2: Goals
PW 2: Discovering The Environment 2: Goals
Exercise 1:
Exercise 2:
Write a program that checks if a number entered by the user is a prime number or not.
The objective of this exercise is to calculate some statistics on a series of real values.
The user should be asked to enter the size and elements of the array.
● Write a program that determines the average of the values in the array.
● In addition to the average, we want to know the smallest and the largest value of the series.
Exercise 4:
● Modify the program to allow unit entry in both lowercase and uppercase.
● Modify the program to allow the user to put blanks between the value and the unit.
● Modify the program so that, after the results are displayed, the program asks the user if they
want to start over. The program then stops if and only if the user types the character "n"
(upper or lower case).
1
UE 204 Introduction to Computer Science 2
Exercise 5:
Given the number of a month and a year read on the keyboard (the month must be between 1 and
12 and the year strictly positive), the following questions are asked to be answered.
● Calculate and display the number of days in this month. Leap years will be taken into account.
Note: A year is a leap year if it is a multiple of 4 without being a multiple of 100 unless it is a multiple
of 400. Thus, 2001 and 1900 are not leap years, whereas 2004 and 2000 are.
● Modify the program to verify the input. If the user enters an incorrect number, the program
should report it and prompt the user for a new month number.
● In addition to the number of days, display the name of the month in full.
With some capital, we want to assess the appropriateness of a fixed rate investment. The interest
rate is assumed to be fixed for the entire term of the investment (if the profit is around a certain
amount). It is also assumed that no transaction (credit or debit) is carried out on the account except
for the deposit of the initial capital and the addition of interest on the anniversary date of the
account.
Under these simplifying assumptions, we know that the interest earned during the year is the
product of the account balance at the start of the year and the interest rate. As the interest is
capitalized, it is the account balance plus interest acquired during the year that serves as the basis for
calculating interest for the following year.
1. Evolution of capital. Write a program which displays on each anniversary date of the
investment the capital and interest acquired during the last year (given: an initial capital, an
interest rate and an investment period entered by the user).
2. Double its initial capital. Write a program that, given an interest rate, displays the number of
years it takes to double the capital.
2