Ask Question
22 September, 00:17

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. 22 September, 00:35
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers