HW02: Arrays#

Purposes of this assignment is to get practice with the following:

  • Arrays

Problem 1#

You are given an array of numbers. Write a Python program to calculate the sum of all the elements in the array and print the result. Use the following arrays to test your program.

  1. [1, 2, 3, 4, 5]

  2. [10, 20, 30, 40, 50]

  3. [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]

  4. [1+2i, 2+3i, 3+4i, 4+5i, 5+6i]

Problem 2#

You are given an array of numbers. Write a Python program to find the largest element in the array and print it. Use the following arrays to test your program:

  1. [1, 2.2, 6.3, 4, 5]

  2. [104, 410, 302, 840, 50]

  3. [3, 36, 9, 12, 415, 18, 21, 24, 27, 30]

Problem 3#

You are given an array. Write a Python program to reverse the order of the elements in the array (in-place, without creating a new array) and print the modified array. Use the same arrays as in Problem 1 to test your program.

Problem 4#

Write a Python program to rotate the array to the right by k steps. Use the same arrays as in Problem 1 to test your program with k=2, and k = 6.