Arab Academy for Science, Technology & Maritime Transport
College of Engineering and Technology
CC212 Applied Programming (Computer Staff)
Week 4 (Functions)
Class Work
1. a) Write a function that gets two numbers (as parameters) and returns their
maximum value.
b) Write a program that reads 5 numbers from the user and uses the above
function to find their maximum.
2. a) Write a function that gets a number (as parameter) and returns its double.
b) Write a program that reads two numbers from the user (x, y) and evaluates
the equation: 2 x + 4 y (Use the above function)
3. a) Write a function that gets two numbers (x, y - as parameters) and returns
the value of: x^y.
b) Write a program that reads 3 values from the used (a, b, c) and uses the
above function to evaluate the equation: (a + b) ^c.
4. Write a C function that calculates the factorial of a number.
5. Solve the following sequence:
Z=1/1! + 2/2! + 3/3! + 4/4! + ... N/N!
Using the factorial function solved in problem 4.
Home Work
1. a) Write a function that gets a number (as a parameter) and returns โ1โ if
the number is odd and โ0โ if the number is even.
b) Write a program that uses the above function to count the number of even
values in an array of 10 elements.
2. a) Write a function that gets a number (as parameters) and prints all its
divisors (assume not more than 10).