You are on page 1of 3

Programming languages – Laboratory 27.03.

2018

Exercise 1
Write a Matlab script that display the first n terms a the Fibonacci series.
Fibonacci series is a series of numbers where the current number is the sum of previous two
terms. For Example: 0, 1, 1, 2, 3, 5, 8, 13, 21, ....

Exercise 2
Write a program to read integer numbers until the number 0 is encountered. The sum of all
numbers read until this point should be printed out.

Exercise 3

Read a positive integer value, and compute the following sequence: If the number is even, halve
it; if it's odd, multiply by 3 and add 1. Repeat this process until the value is 1, printing out each
value. Finally print out how many of these operations you performed.

Typical output might be:

Inital value is 9
Next value is 28
Next value is 14
Next value is 7
Next value is 22
Next value is 11
Next value is 34
Next value is 17
Next value is 52
Next value is 26
Next value is 13
Next value is 40
Next value is 20
Next value is 10
Next value is 5
Next value is 16
Next value is 8
Next value is 4
Next value is 2
Final value 1, number of steps 19
If the input value is less than 1, print the message ‘Error’
Exercise 4

Celsius to Fahrenheit Conversion Tables.

For values of Celsius from -20 to +30 in steps of 5, produce the equivalent Fahrenheit temperature.
The following formula converts C (Celsius) to F (Fahrenheit).

For values of Fahrenheit from -10 to 100 in steps of 5, produce the equivalent Celsius temperatures.
The following formula converts F (Fahrenheit) to C (Celsius).

Exercise 5
Pascal’s triangle is a number triangle with numbers arranged in staggered rows such that:
!
! !

This equation is the equation for a binomial coefficient. You can build Pascal’s triangle by
adding the two numbers that are diagonally above a number in the triangle. An example of
Pascal’s triangle is shown below.

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Write a program that prints out Pascal’s triangle. Your program should accept a parameter that
tells how many rows of the triangle to print.

You might also like