Exercise: Exercise 1: Calculate The Price TTC of An Item From Its Price HT, With A Rate of VAT To 19.6%
Exercise: Exercise 1: Calculate The Price TTC of An Item From Its Price HT, With A Rate of VAT To 19.6%
Exercise 1: Calculate the price TTC of an item from its price HT, with a rate of VAT to 19.6%.
Algorithm
Solution:
Calculation and simple display
-->HT=540;
-->TTC=HT*1.196
TTC =
645.84
Function:
-->function TTC=f(HT);
-->TTC=HT*1.196;
-->endfunction
-->f(540)
ans =
645.84
-->f(3789)
ans =
4531.644
Exercise 2: Convert a given time into seconds, hours, minutes and seconds.
Algorithm
- Read the time in seconds, put it in t
- Put q in quotient of t by 60 (number of minutes)
- Put in s the remainder (number of seconds)
- Put in h the quotient of q by 60 (number of hours)
- Put in m the remainder (minutes remaining)
- Display hours, minutes, seconds
Scilab code
Calculation and simple display:
t = 12680;
q = floor(t/60);
s = t-60*q;
h = floor(q/60);
m = q-60*h;
disp([h,m,s])
Function
function y=f(t)
q = floor(t/60);
s = t-60*q;
h = floor(q/60);
m = q-60*h;
y=[h,m,s]
endfunction
disp(f(12680))
Exercise 3: Calculate the hypotenuse of a triangle knowing the two sides of the right angle.
Exercise 4: Calculate the squares of the natural integers from 1 to 100 and store the results
in a vector c. Display the value of c(37).
Display the index and the values of the calculated sequence, and then plotting them.
Exercise 6: Calculate the quotient q in the division of a positive number n by 11, by the
method of successive subtractions.
Exercise 7: Bob placed € 5,000 in compound interest with a rate of 2.7% per year in 2009.
- Calculate the amounts obtained for the next 20 years,
- Draw a graph depicting the total amount obtained annually,
- Write a program to find the year that Bob will get € 7,000.
Exercise 10: Find an approximate value of the golden ratio, the positive solution of the
following equation
x2 = x + 1
as follows
1) Define the function f(x) = x 2 - x - 1.
2) Plot the graph of this function on the interval [-5, 5]
3) Write a program allowing, by dichotomy method, to frame the desired solution in a
range of amplitude 10^- 4 starting from the values 1 and 2.
Exercise 11: The Syracuse sequence is defined by: u1 is given and for n 1,
un
if u n even
u n+1 = 2
3u n + 1 otherwise.
Calculate the terms and verify that, whatever u1, we always arrive at 4, 2, 1. To do this, one
defines the Syracuse function which will give, according to the first term, the rank at which
one arrives at 1 and all term of that sequence.
(http://en.wikipedia.org/wiki/Collatz_conjecture)
( )
b) The graph of function y = f(x) = x + ln x - 1 on [1, 5]; and it is red.
2x + 3
Exercise 16: Write a program that calculates the coefficients of the Newtonian binomial
expansion (that is Cnk, k=1,…,n) with n = 1,2, ..., 10, and display as a table (Pascal's triangle).
Exercise 17: Write a program to create a function divide that computes the quotient and
the remainder in the division of a by b, where a and b are two positive integers. Use this
function to calculate the quotient and the remainder in the division of 1224 by 15.
Exercise 18: Write a prem function that checks whether a given integer is prime number or
not? Use this function to verify the integer a = 232 + 1 is prime?
Exercise 20: Create a UCLN function to find the greatest common divisor of given two
integers a, b. Use this function to calculate the greatest common divisor of two numbers
595 and 10200.
Exercise 21: Create a BEZOUT function to find the Bézout coefficients of given two positive
numbers a and b, that are integer numbers u and v such that au + bv = UCLN(a, b). Use this
function to find the Bézout coefficients of 595 and 10200.
Exercise 22: Mersenne numbers are formed by the formula n = 2p - 1, where p is a prime
number. Write a program to determine which Mersenne number is prime, for p < 40.