pass 2-d array to function in turboo c++

Pages: 12
#include<iostream.h>
#include<conio.h>

int BiggestEntry( int arr[3][4] );
// what about " two parameters representing the row and column"?

void main()
{
clrscr();
int a, b, x[3][4]={12,32,43,5,1,14,25,60,16,23,67,97}, max;

for (a=0;a<3;a++)
for (b=0;b<4;b++)
max = (x[3][4]); // out of range error: array x[3][4] does not have element x[3][4]
// besides, setting max to same value for 12 times is excessive

// the function BiggestEntry is never called by this program

cout<<"Biggest entry is="<<max<<endl;
getch();
}

int BiggestEntry(int arr[3][4])
{
int i,j,Biggest;
Biggest=arr[0][0];

for (i=0;i<3;i++)
for (j=0;j<4;j++)
if (arr[i][j] > Biggest)
Biggest = arr[i][j];

return Biggest;
}
please help me to fix this

output is (the biggest entry is=0)
this is the question



Write a function called biggestEntry( ) that uses a two dimensional array and two parameters representing the row and column capacities. The function should return the value of the biggest entry in the array. For example, a program that uses the function biggestEntry follows.
int main()
{
int x[2][3] = {{1,2,3},{4,7,3}};
biggestEntry(x, 2, 3)
It should print 7 (since 7 is the biggest entry in 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
#include<iostream.h>
#include<conio.h>

using namespace std;

#define ROW_COUNT   3
#define COL_COUNT   4

int BiggestEntry( int arr[ROW_COUNT][COL_COUNT], int row_count, int col_count );
// what about " two parameters representing the row and column"?

void main()
{
  int a, b, x[ROW_COUNT][COL_COUNT] = 
  {
    12,32,43,5,
    1,14,25,60,
    16,23,67,97
  }; 
  
  int max = BiggestEntry(x, ROW_COUNT, COL_COUNT);

  cout << "Biggest entry is = " << max << endl;
  getch();
}

int BiggestEntry(int arr[ROW_COUNT][COL_COUNT], int row_count, int col_count)
{
  int row, col, Biggest;
  Biggest = arr[0][0];

  for (row = 0; row < row_count; row++)
    for (col = 0; col < col_count; col++)
      if (arr[row][col] > Biggest)
        Biggest = arr[row][col];

  return Biggest;
} 
i tried your programm there is an error
i.e " Function(BiggestEntry) should have a prototype

how do i remove this error
Do not double-post. First thread: http://www.cplusplus.com/forum/beginner/184949/
I don't understand your compiler. The prototype is on line 9.
Turbo C++ is probably ancient, unsupported, and unable to compile modern C++ code. There are other, free and up to date compilers and IDE's available.


The homework assignment most likely expects the function to use a pointer argument . A link that I did post to the other thread does explain some of it.
It is true that Turbo C++ is not compatible with modern C++.

However, just for interest I tried the code posted by Thomas1965 above in a DOS version of Turbo C++ 3.0 (dated 1992). It objected to only one line:
using namespace std; When I removed that line, the code compiled and executed with no problems.
http://cpp.sh/5kdn

it gives wrong output i.e The biggest entry is=0

please help me to solve this

#include<iostream>
using namespace std;
#define row 3
#define col 4
void BiggestEntry(int arr[row][col],int r,int c);
int main()
{
int a,b,x[row][col]={{12,32,43,5},{1,14,25,60},{16,23,67,97}},max;
for(a=0;a<3;a++)

for(b=0;b<4;b++)
BiggestEntry(x,3,4);
cout<<"Biggest entry is="<<max<<endl;
}
void BiggestEntry(int arr[row][col],int r,int c)
{
int i,j,Biggest;
Biggest=arr[0][0];
for(i=0;i<r;i++)
for(j=0;j<c;j++)
if(arr[i][j]>Biggest)
Biggest=arr[i][j];
}
Where is max assigned a value in main?

The function should return the value of the biggest entry in the array.

Where does BiggestEntry return a value?
Last edited on
please (cire) correct my programm
in http://cpp.sh/5kdn
Last edited on
Please make an attempt to correct it yourself given the questions I asked previously.
i dont know how?
Then you should probably review material you've already learned.
why dont you fix the error?
cout<<"Biggest entry is="<<max<<endl;
problem is just there
Last edited on
this is the question


Write a function called biggestEntry( ) that uses a two dimensional array and two parameters representing the row and column capacities. The function should return the value of the biggest entry in the array. For example, a program that uses the function biggestEntry follows.
int main()
{
int x[2][3] = {{1,2,3},{4,7,3}};
biggestEntry(x, 2, 3)
It should print 7 (since 7 is the biggest entry in the array)

The problem is not just there, as one can infer from the questions I previously asked.
i just want correct output
Post your updated code. Then, we can start troubleshooting it.
Pages: 12