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

please help me to solve this



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)
Have you studied the relationship of arrays and pointers?
yes
Last edited on
i tried to create this programm


#include<iostream.h>
#include<conio.h>
int BiggestEntry(int arr[3][4]);
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]);
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;
}



it gives output
(The biggestentry is=0)
i dont know why is this happening
First, please do use code tags when posting code.
See http://www.cplusplus.com/articles/jEywvCM9/

Your code, in tags and with some whitespace:
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
#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;
}



See http://www.cplusplus.com/doc/tutorial/pointers/
There is a section "Pointers and Arrays"

Even more to the point is: https://www.eskimo.com/~scs/cclass/notes/sx10f.html
Last edited on
PLease fix the above programm
and correct my programm
Last edited on
Topic archived. No new replies allowed.