0% found this document useful (0 votes)
33 views3 pages

Programming Languages - 27032018

The document outlines 5 programming exercises: 1) Write a Matlab script to display the first n terms of the Fibonacci series. 2) Write a program to read integers until 0 and print their sum. 3) Read a positive integer, repeatedly halve even numbers and multiply odd numbers by 3 and add 1 until reaching 1, printing each value and number of steps. 4) Generate Celsius to Fahrenheit and Fahrenheit to Celsius conversion tables from given ranges and step sizes. 5) Write a program to print Pascal's triangle for a given number of rows by adding diagonally above numbers.

Uploaded by

Irina Stanciu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Programming Languages - 27032018

The document outlines 5 programming exercises: 1) Write a Matlab script to display the first n terms of the Fibonacci series. 2) Write a program to read integers until 0 and print their sum. 3) Read a positive integer, repeatedly halve even numbers and multiply odd numbers by 3 and add 1 until reaching 1, printing each value and number of steps. 4) Generate Celsius to Fahrenheit and Fahrenheit to Celsius conversion tables from given ranges and step sizes. 5) Write a program to print Pascal's triangle for a given number of rows by adding diagonally above numbers.

Uploaded by

Irina Stanciu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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