8.3 - Challenges

Create a sub-program for each challenge below. It must match the provided dataflow.

You should test each sub-program fully to ensure it works as expected.

1 - Even or odd number

Write a procedure that will check if a number is odd or even and display the result.

Data flow

IN: num

2 - Count even numbers

Write a function that counts how many numbers in an array are even.

Data flow

IN: num_array

OUT: even_count

3 - Minutes and seconds

Write a function that converts a total number of seconds into minutes and seconds.

Data flow

IN: seconds

OUT: minutes, remaining_seconds

4 - Remove decimal

Write a function that returns the whole number part of a decimal.

Data flow

IN: decimal_number

OUT: integer_part

5 - Count multiples of 5

Write a function that counts how many numbers in an array are divisible by 5.

Data flow

IN: num_array

OUT: count

6 - Share equally

Write a function that calculates how many sweets each child gets when a number of sweets is shared between children.

Data flow

IN: sweets, children

OUT: sweets_per_child

7 - Teams with odd goals

Given arrays of teams and goals, write a procedure to display the teams that scored an odd number of goals.

Data flow

IN: teams, goals

8 - Get even number

Write a function that will ask the user to enter a number and keep asking until they enter an even number.

Data flow

OUT: even_number

9 - Highest even number

Write a function to find the largest even number in an array.

Data flow

IN: numbers

OUT: highest_even_number

10 - Highest remainder

Write a function to find the number with the largest remainder when divided by 5.

Data flow

IN: num_array

OUT: max_remainder_num

11 - Day of the week

Assuming that the first of January is a Monday.

Write a function to convert a day number (e.g. 1–365 for a year) to which day of the week it lands on  1 = Monday, 2 = Tuesday …).

Data flow

IN: day_number

OUT: day

Target

Design and write functions