hello,I have this program which reads elements from the user for an array of [4][4]. and i made functions to enter elements and find max and find min element. i'm trying to write a 4th functions to sum and print the summation of both min element and max element. but i can't figure it out. any ideas?
#include <iostream>
usingnamespace std;
int MaxE(int arr[4][4])
{
int max=arr[0][0];
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(arr[i][j]>max)
max=arr[i][j];
}
return max;
}
int MinE(int arr[4][4])
{
int min=arr[0][0];
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(arr[i][j]<min)
min=arr[i][j];
}
return min;
}
void read(int arr[4][4])
{
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
cout<<"Enter element ["<<i+1<<","<<j+1<<"] : ";
cin>>arr[i][j];
}
}
void printArray
int main()
{
int a[4][4],SUM;
cout<<"Please enter the elements of 2D Array "<<endl;
read(a);
cout<<endl;
cout<<"The Sum of Max and Min element is "<< MaxE(a) + MinE(a)<<endl;
return 0;
}
I don't get it either. do you want the lowest and highest 2 values added up? You have it, if its not working, I don't see any errors? If you need it in a function, you can do that, just move the print statement you already have into a function.
if you want the sum of everything, you can do that too.
if you want to combine them and find the lowest and highest in a single loop, add & print, its just a little variation on what you already did.
i need to call a funtion to take both max element and min element and sum them together and then print the result all that using one function. i did that with out a function cout<<"The Sum of Max and Min element is "<< MaxE(a) + MinE(a)<<endl;
i want a void function to do that line .. i just can't tell how .. seriously
oh it was that easy lol i'm sorry, i was having an error about calling functions into a 3rd function, i thought it was alot more complicated. sorry once again, cheers bro :)