Ask Question
23 January, 11:52

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.

+5
Answers (1)
  1. 23 January, 13:12
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers