MULTIARRAY Functions

Hi again guys,

I'm having trouble to compile my program as there are some errors & i dun really understand wad the compiler output really mean for.

If u copy&paste my code on ur compiler u could see the highlighted syntax.

for array,when passing into function..normally is <datatype><functionname><int[],array_size> but how about multi array?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include<iostream>

using namespace std;

void sum(int [],int [],int []);

int main()
{
	int max1[3][3]={{3,4,2},{2,6,8},{7,3,9}};
	int max2[3][3];
	int max3[3][3];
	for(int a=0;a<3;a++)
	{
		for(int b=0;b<3;b++)
		{
			cout<<"Enter value:\n";
			cin>>max2[a][b];
		}
	}
	sum(int max1,int max2,int max3);
	cout<<"Your product of addition is:"<<max3<<endl;
	


	system("pause");

	return 0;
}
void sum(int max1[],int max2[],int max3[])
{
	for(int c=0;c<3;c++)
	{
		for(int d=0;d<3;d++)
		{
			max3[c][d]=max1[c][d]+max2[c][d];
		}
	}
}
I don't think you have the slightest clue of what you're doing.

From the looks of it, you're trying to perform matrix addition without knowing how multidimensional arrays work.

Just look at line 21; what are you trying to do? Print the address of max3?

Do some extensive reading, and then take a look at your fixed code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>

using namespace std;

void sum(int[][3], int[][3], int[][3]);

int main()
{
    int max1[3][3] = { { 3, 4, 2 }, { 2, 6, 8 }, { 7, 3, 9 } };
    int max2[3][3];
    int max3[3][3];

    for(int a = 0; a < 3; a++)
    {
        for(int b = 0; b < 3; b++)
        {
            cout << "Enter value:" << endl;
            cin >> max2[a][b];
        }
    }

    sum(max1, max2, max3);
    
    cout << "Your product of addition is:" << endl;

    for(int a = 0; a < 3; a++)
    {
        for(int b = 0; b < 3; b++)
        {
            cout << max3[a][b] << ' ';
        }

        cout << endl;
    }

    cin.get();

    return 0;
}

void sum(int max1[][3], int max2[][3], int max3[][3])
{
    for(int c = 0; c < 3; c++)
    {
        for(int d = 0; d < 3; d++)
        {
            max3[c][d] = max1[c][d] + max2[c][d];
        }
    }
}
thks,so for the void function at line 41.

For example,int max1[][3]..we juz nid to pass in columns?
Topic archived. No new replies allowed.