biggest element of the line and column of the 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
using namespace std;

void Lines(int mat[2][2], int vect1[])
{
    int i, j;
    vect1[0] = 0;
    for(i=0; i<2; i++)
    {
        for (j=0; j<2;j++)
            {
                if( mat[i][j] > vect1[0] )
                {
                    vect1[i] = mat[i][j];
                }
            }

    }
    cout << "biggest element of the line: \n";
    for (int i=0; i<2; i++)
    {
        cout << vect1[i] << "\n";
    }
}

int Columns(int mat[2][2], int vect2[])
{
    int i, j;
    vect2[0] = 0;
    for(i=0; i<2; i++)
    {
        for(j=0; j<2; j++)
        {
            if( mat[i][j] > vect2[0] )
            {
                vect2[i] = mat[i][j];
            }
        }
    }
    cout << "biggest element of the column: \n";
    for (int i=0; i<2; i++)
    {
        cout << vect2[i] << " ";
    }
}

int readarray(int mat[2][2])
{
    for (int i=0; i<2; i++)
    {
        for (int j=0; j<2; j++)
        {
            cout << "insert element: " << endl;
            cin >> mat[i][j];
        }
    }
}


int main()
{
    int array[2][2], vector1[2], vector2[2];
    readarray(matriz);
    lines(matriz,vector1);
    lines(matriz,vector2);
    return 0;
}



The code works, but if the elements in the second line are minor than the first line, the code does not show expected. Any idea why? Thx :)
The code does not compile.

Line 62: array is supposed to be matriz
Line 64,65: lines is supposed to be Lines. Note that current C/C++ is case sensitive.

The problem is on line 12,34:
vect1[0] is supposed to be vect1[i]
and
vect2[0] is supposed to be vect2[i]

Further more: Remove line 7,29.
Write after line 9 vect1[i] = 0;
and
Write after line 31 vect2[i] = 0;
@coder777
Note that current C/C++ is case sensitive.


you just frightened me!
Topic archived. No new replies allowed.