mardi 27 juin 2017

passing a 2D array to a function and multiplying it by two

so i Am trying to pass this array and then multiply it by 2. My code works, but it multiples it by 4 instead i think its because of the for loop inside another for loop. can someone explain how to fix this?

5x5 array:

int numbers  [5][5] = { { 1,3,5,7,9},{-2,-4,-6, -8, -10},{3,3,3,3,3},{ 55, 77, 99, 22, 33 },{ -15, -250, -350, -450, -550 } };



    // function
    int multiply_bytwo(int n[5][5])
    {

        int total_times = 0;
        for (int row = 0; row < 5; row++)
        {


            for (int col = 0; col < 5; col++)
            {
                n[row][col] = n[row][col] * 2;
            }

            return total_times;
        }
    }

Aucun commentaire:

Enregistrer un commentaire