0% found this document useful (0 votes)
17 views1 page

3 - Functions (Methods)

Uploaded by

Aida
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)
17 views1 page

3 - Functions (Methods)

Uploaded by

Aida
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/ 1

Fundamentos de programación

Worksheet – Functions (Methods)

1. Create a program that asks for three integers and identifies which one is the highest. For
this, we will use the max method, which receives two integers as parameters and returns
the higher one.

2. Write a program that converts inches to centimeters, by means of a method


inchesToCentimeters (One inch is equal to 2.54 centimeters)

3. Write a program that calculates the volume of a cylinder, using getCylinderVolume. The
user must enter the radius of the base and the height of the cylinder.
Formula: 𝑉 = 𝜋𝑟 2 ∗ ℎ

4. Create a program that requires four points in 2D space and determines whether they form
a rectangle or a square with the functions isRectangle and isSquare.

5. Write a program that reads the 3 coordinates of a vector in a three-dimensional space and
calculates the corresponding unit vector (vector with the same direction and length 1),
which is obtained by dividing each coordinate of the original vector by its length. If the
entered vector is (0, 0, 0), the program will indicate that there is no unit vector. We will
make use of the getLength method, which will take the coordinates of the vector and
return the length of the vector or 0 when the vector is null.

6. Create a program that checks if a given date is correct. For this we will enter the day,
month and year. We will use the isValidDate and isLeapYear methods.

7. Write a program that calculates the sum of the multiples of 5 between two values a and b.
Negative values of a and b will not be allowed and a must be lower than b, otherwise their
values will be swapped. The isMultiple function will be used, to which both the number we
want to check and the number of which it must be a multiple will be passed.

8. Write a method that returns true when a number received is prime and false when it is
not. Then, using this method, write a program that displays the prime numbers between
two numbers. The results will be displayed on the screen in 8 columns.

9. Write a program that shows the factorial of a given number by using the recursive method
factorial.

10. Create a program that displays on screen the first 15 terms of the Fibonacci sequence. For
this we will need the recursive method Fibonacci, which returns the value of the nth
element of the Fibonacci sequence.

You might also like