Hey, I have been browsing the site for awhile and find it quite impressive. I couldn't find an article that quite helped me out. I was curious as how to change the following program into pointer notation. Replies are much appreciated.
using namespace std;
const int row = 4;
const int col = 5;
int findMax(int [row][col]);
int findMaxC(int [row][col]);
int main()
{
int nums[row][col] = {16, 22, 99, 4, 18, -258, 4, 101, 5, 98,
105, 6, 15, 2, 45, 33, 88, 72, 16, 3};
int rn, cn;
for (rn = 0; rn < row; rn++)
{
for (cn = 0; cn < col; cn++)
cout <<setw(4) <<nums[rn][cn];
cout <<endl;
}
rn=0;
cn=0;
cout <<endl;
findMaxC(nums);
cout <<"\nThe max value in the array is: " <<findMax(nums)
<<endl <<endl;
system("pause");
return 0;
}
int findMax(int n[row][col])
{
int i, j, max=0;
int maxrow=0;
for (i=0;i<4;i++)
{
for (j=0;j<5;j++)
{
if (n[i][j] > max)
{
max = n[i][j];
}
if (n[i][j] > maxrow)
{
maxrow = n[i][j];
}
}
cout <<"Maximum number in Row number " <<i+1 <<" is " <<maxrow <<endl;
maxrow=0;
}
return max;
}
int findMaxC(int n[row][col])
{
int i, j, maxcol=0;
for (j=0;j<5;j++)
{
for (i=0;i<4;i++)
{
if (n[i][j] > maxcol)
{
maxcol = n[i][j];
}
}
cout <<"Maximum number in Col number " <<j+1 <<" is " <<maxcol <<endl;
maxcol=0;
}
cout <<endl;
return 0;
}
Thanks again.