2D arrary

closed account (ETA9216C)
how would one write a function that doubles every element of a 20×10 2-dimensional array?
this is what i've got so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
double arrary [i][j];

for(double i=0; i<20;++i)
{
            for (double j=0;j<10;++j)
                      {
                       array[i][j] =
                     }
{
       

for(double i=0;i<20;++i)
      {
                 for (double j=0;i<10;++j)
                         {
                                    cout<<array[i][j];
                             }
}




Last edited on
closed account (ETA9216C)
Can someone correct me if i'm wrong? I'm trying to study for a test.Thank you in advance.
You can't use floating-point numbers as array indices, only integers.
closed account (ETA9216C)
how would it be done?
closed account (N36fSL3A)
Change 'i' from a double to an int.

for(int i=0;i<20;++i)

-----
Is this what you want?

1
2
3
4
5
6
7
8
9
int arr[i][j];

for(unsigned int n = 0; n < i; ++i)
{
    for(unsigned int m = 0; m < j; j++)
    {
        arr[n][m] *= 2;
    }
}
Last edited on
closed account (ETA9216C)
i think so.
Topic archived. No new replies allowed.