Lab April 17

Problem 1 Write the following functions:

1. Function sumEven that accepts two parameters - integer array and its size and returns the sum of the even elements of the array. If there are no even elements, the function returns -1.

2. Function countEventhat accepts two parameters - integer array and its size and returns the number of the even elements of the array.

3. Function averageEven that accepts two parameters - integer array and its size and returns the average of the even elements. If there are no even elements the function returns -1. This function MUST use functions sumEven and countEven to perform the task

Write a program that randomly generates the size of the array (integer between 5 and 20) and an array of integers between 0 and 10. Use function make_array we wrote in class. Print randomly generated an array using function print_array we wrote in class. The program will use function averageEven to find the average of the even elements

Problem 2

1. Function count_even_divisor that accepts one integer parameter num and returns the number of even divisors of parameter num

2. Function array_even_divisor that accepts two parameters - integer array and its size and for each element of the array prints the number of the even divisors. Use function count_even_divisor.

Write a program that randomly generates the size of the array (integer between 5 and 20) and an array of integers between 0 and 100. Use function make_array we wrote in class. Print randomly generated an array using function print_array we wrote in class. The program will use function array_even_divisor to print even the number of even divisors of each element of the array. Make sure that you specify the case with no even divisors.

Problem 3 Selection Sort:
Write a program that sorts the array of integers using Selection Sort.
Definition: Selection Sort works as follows: first find the smallest element in the array and exchange it with the element in the first position, then find the second smallest element and exchange it with the element in the second position, and continue in this way until the entire array is sorted. You would need to write the following functions:

  • Problem 4:
    Write the following functions:

  • Problem 5
    Write main to test your program. You can also write functions make_array and print_array.
  • In this program you can assume that ALL INPUTS ARE POSITIVE NUMBERS. Write the following functions: