Here are some simple exercises for simple programming.
Construct the following programs:
- A check sum function that takes input three integers
(
a,bandc) and returns a boolean value if - A check divisible function that takes as input two integers
(
aandb) and returns a boolean values ifais not divisible byb. - A max function that returns the maximum of two numbers
aandb. - A min function that returns the minimum of two numbers
aandb.
- A check sum function that takes input three integers
(
Construct the following programs:
- A program that computes the factorial for a given input
ni.e. multiples all the numbers less than or equal ton. - A program that computes the even factorial
(multiplies the even numbers only)
for a given input
n. - A program that computes the odd factorial
(multiplies the odd numbers only)
for a given input
n.
- A program that computes the factorial for a given input
Construct a program that calculates the number of the fibonacci sequence.
Construct a program that computes the combinatorial of two integers
nandm, as given by:This program should return an error if .
- Hint
- Think how you will encapsulate/report/handle the error
Construct a program that returns a string message if the user supplied year is a leap year.
Construct a program that returns true if a given number is prime.
Construct a program that, given a list
xsand an integern, will keep only the firstnelements inxsand throw away everything after that. If there are less thannelements then the entire list should be returned.Construct a program that will merge two lists,
xsandys, together by alternating elements from each list. If one of the lists runs out of elements first then the remaining elements comes from the other list.Construct a program that will drop every second element from a list.
Construct the following programs that will compute the dot product of two lists
xsandys, that contain real numbers.The dot product is the sum of multiplication of each element in
xsby elements inys. Should one list be longer than the other you must either: truncate the longer list, or right-pad the short list with 0s.