Jump to content

Add up elements of 1d and 2d array


Recommended Posts

Hello guys! I've got a problem regarding arrays.

local $_array1[4][4] = [[1,4,2],[4,6,3],[6,1,7]]
local $_array2[4] = [6,1,2]

How do i add up the elements form the first array, to the elements of the second array,and return the final values into a single string? I've posted an image, so you could know what am i talking about. It seems a little bit complicated to me, but i hope this forum will lead me to the correct answer.

Thanks in advance.

Here's the image :scheme.png

Link to comment
Share on other sites

Almost the same.

#include <AutoItConstants.au3>
#include <Array.au3>

Local $_array1[3][3] = [[1, 4, 2], [4, 6, 3], [6, 1, 7]]
Local $_array2[3] = [6, 1, 2]
Local $a_Result[3][3]

For $i = 0 To UBound($_array1) - 1
    For $j = 0 To UBound($_array1, $UBOUND_COLUMNS) - 1
        $a_Result[$i][$j] = $_array1[$i][$j] + $_array2[$j]
    Next
Next
_ArrayDisplay($a_Result)

Local $s_Result = _ArrayToString($a_Result, "", -1, -1, "")
MsgBox(0, '', $s_Result)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...