Skip to content

Latest commit

 

History

History
27 lines (14 loc) · 2.79 KB

S05-EN-arrays-and-matrices.md

File metadata and controls

27 lines (14 loc) · 2.79 KB

Arrays and Matrices

  1. E01-max-value: Write a function that takes an array as input and returns the maximum value in it.

  2. E02-greater-than-n: Write an action that takes an array A and an integer N as input and returns (using reference parameters) the number of elements in A greater than N and the percentage of elements greater than N.

  3. E03-palindrome-check: Write a function that takes a string as input and returns true if it is a palindrome.

  4. E04-even-odd-count: Write an action that takes an array of integers as input and returns (using reference parameters) the number of even and odd elements in the array.

  5. E05-power-of-two: Write an action that takes an array of integers A and an element K as input and places K in the power of two positions in the array (1, 2, 4, 8, . . .).

  6. E06-circular-shift: Write an action that takes an array A of integers and an integer K as input and performs K circular shifts of A to the left. Example: If A = {4, 6, −1, 2} and K = 2, the final value of A should be {−1, 2, 4, 6}.

  7. E07-most-frequent: Given an array with values between 0 and 100, write a function to determine the most frequently occurring value.

  8. E08-sum-pairs: Write a function that takes an array of integers A and a number K as input and determines if there are two values in A that sum up to K. Example: If A = {4, −1, 6, 8, 10, 3} and K = 2, the function should return true because −1 + 3 = 2.

  9. E09-merge-arrays: Given two sorted arrays of integers A and B, write a function to obtain a third array C that contains all the elements of A and B in sorted order. Example: If A = {1, 4, 9} and B = {2, 5, 10, 12}, the result should be C = {1, 2, 4, 5, 9, 10, 12}.

  10. E10-transpose-matrix: Write a function that takes a square matrix of N × M as input and returns the transposed matrix of M × N. Remember that the transposed matrix is one where rows are swapped with columns. Example: If the original matrix is A = {{1, 5}, {2, 3}}, the function should return A = {{1, 2}, {5, 3}}.

  11. E11-secondary-diagonal: Write a function that takes a square matrix as input and returns the sum of the elements of the secondary diagonal.

  12. E12-swap-rows: Write an action that takes a matrix (with an even number of rows) as input and swaps the even and odd rows. Example: If the matrix is {{4, 2}, {1, 2}, {6, −1}, {3, 5}}, the resulting matrix should be {{1, 2}, {4, 2}, {3, 5}, {6, −1}}.

  13. E13-pharmacy-stock: Create a program to keep track of a pharmacy's inventory. Given three arrays with the names of medicines, the quantity, and the value of each one, the program should calculate the total value of the inventory, the value of the stock of each medicine, and be able to sort the medicines by the quantity in stock.