Ask Question
14 November, 16:40

Assume you are given an int variable named sum and a 2-dimensional array of ints that has been created and assigned to a2d. Write some statements that compute the sum of all the elements in the entire 2-dimensional array and assign the value to sum.

+2
Answers (1)
  1. 14 November, 16:49
    0
    array_2d = [[7, 20],[13, 4],[25, 679]]

    total = 0

    for row in array_2d:

    total + = sum (row)

    print (total)

    Explanation:

    * The code is in Python.

    Since sum () is a built-in function in Python, I used total instead.

    - Create a for loop that iterates through the 2d array, visits each row

    - Add the values of the element in each row - using sum () function - to the total variable

    - When the loop is done, print the total
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Assume you are given an int variable named sum and a 2-dimensional array of ints that has been created and assigned to a2d. Write some ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers