help guys! functions!

This program enables me to find the biggest number of all rows and columns and the overall highest number. How can I convert this exact code to a function of maxs() ? HELP PLEASE

#include<iostream>
using namespace std;
int main()
{
const int numrows=4;
const int numcols=5;
int maxs[numrows][numcols]={{12, 23, 6 , 34, 5},
{61, 9, 14, 54, 10},
{3, 21, 5, 67, 44},
{21, 89,13, 49, 90}};
int row,col,largestrows,largestcols,largest;
for(row=0;row<numrows;row++)
{
largestrows=maxs[row][0];
for(col=1;col<numcols;col++)
if(largestrows<maxs[row][col])
largestrows=maxs[row][col];
cout<<"The largest integer in the row"<<row+1<<" "<< "is "<<largestrows<<endl;
}
for(col=0;col<numcols;col++)
{
largestcols=maxs[0][col];
for(row=1;row<numrows;row++)
if(largestcols<maxs[row][col])
largestcols=maxs[row][col];
cout<<"The largest integer in the column"<<col+1<<" "<< "is "<<largestcols<<endl;
}
if(largestrows>largestcols)
largest=largestrows;
else
largest=largestcols;
cout<<"The largest integer of all data is "<<largest<<endl;
return 0;
}
That depends on what you want the function to do. If it is to print things about an array of your choice, before main() write
1
2
3
void print_stuff_about_array( int maxs[][5] ){
   //here copy all the code in main from declaration of maxs, to return 0 (not inclusive).
}


If you want it to store the results somewhere, you'll need some changes, of course.

By the way, when you post code, use [code][/code] tags
Last edited on
Topic archived. No new replies allowed.