Assignment
Assignment
ASSIGNMENT (9)
(1) Write a program that calculates the sum of all the numbers between M and
N, where M and N are two integers entered by the user.
(2) Write a program that calculates the factorial of a number (N), using the
following formula: [ n*(n-1)*(n-2)* … *2*1], where N is an input entered
by the user. (e.g. 5! = 5*4*3*2*1 = 120)
(3) Write a program that calculates both the sum and the factorial of all the
numbers between 1 and (m), where the value of (m) is entered by the user.
(4) Modify the previous program to change the layout of the table, as shown:
Page 1 of 3
COURSE: INTRODUCTION TO PROGRAMMING (BIS227E)
LECTURERS: DR. ALI ALLAM / DR. MOHAMED SOBHY
(5) Write a program that calculates and prints the result of the following
expression:
1 - 2 + 3 - 4 + 5 - 6 + … (m)
where (m) is an input entered by the user.
(6) A client receives a bank loan to buy a car. The banker enters the loan
amount and the interest rate, then the program prints a detailed statement of
the total amount required to be paid along a whole year (i.e. up to 12
months), as shown below. The following formula is used by the bank to
calculate the total amount according to the number of months:
Amount = Loan (1 + Interest) month
Note: Use the PHP function pow(base,exp). i.e. pow(5,3) 53
Page 2 of 3
COURSE: INTRODUCTION TO PROGRAMMING (BIS227E)
LECTURERS: DR. ALI ALLAM / DR. MOHAMED SOBHY
(7) Given that a car depreciates over 5 years. The customer is asked to enter its
original price (e.g. $17000), as well as its residual value (e.g. $2000).
Write a program to calculate and print the following:
- The car value at the beginning of each year.
- The annual depreciation expense.
- The accumulated depreciation.
- The car value at the end of each year.
Given that:
𝑃𝑟𝑖𝑐𝑒 𝑜𝑓 𝑓𝑖𝑥𝑒𝑑 𝑎𝑠𝑠𝑒𝑡 − 𝑅𝑒𝑠𝑖𝑑𝑢𝑎𝑙 𝑣𝑎𝑙𝑢𝑒
Annual depreciation =
𝑙𝑖𝑓𝑒𝑡𝑖𝑚𝑒 𝑜𝑓 𝑎𝑠𝑠𝑒𝑡 (𝑦𝑒𝑎𝑟𝑠)
Car value at any given time = Original price – Accumulated depreciation
The output should look like the following example:
Page 3 of 3