How can one create an array of two functions which accepts integer array along with its size as two input variables, and return maximum or minimum respectively, and showing its function prototype
This is what i have so far, but is not fully right :(
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int findMax(int[],int n);
int max=0;
int n;
cout << " Enter an integer that represents the size of input variables: ";
cout << endl;
cin >> n;
for(int i = 1; i < n; i++)
{
if(array[i] > max)
cout << max = array{i};
}
system("Pause");
return 0;
}
int findMax(int [], int n)
{
return max;
}
struct A
{
staticint f1( int [], int ) { std::cout << "A::f1\n"; return ( 1 ); }
staticint f2( int [], int ) { std::cout << "A::f2\n"; return ( 2 ); }
};
int ( *fp[] )( int [], int ) = { A::f1, A::f2 };
int a[2];
for ( int i = 0; i < 2; i++ ) fp[i]( a, 2 );
my problem is how to edit this program. I don't need a new program with function i never learn in my class yet. may you please show me how to solve the question using my program
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int findMax(int[],int n);
int max=0;
int n;
cout << " Enter an integer that represents the size of input variables: ";
cout << endl;
cin >> n;
for(int i = 1; i < n; i++)
{
if(array[i] > max)
cout << max = array{i};
}
system("Pause");
return 0;
}
int findMax(int [], int n)
{
return max;
}
#include <iostream>
#include <cstdlib>
usingnamespace std;
int FindMax( constint [], int );
int FindMin( constint [], int );
int main ()
{
constint N = 5;
int a[N];
for( int i = 0; i < N; i++ )
{
cout << "Enter the values to find the maximum or minimum among them." << endl;
cin >> a[i];
}
cout << " The maximum in an array is : " << FindMax( a, N ) << endl;
cout << " The minimum in an array is : " << FindMin( a, N ) << endl;
system("Pause");
return 0;
}
int FindMax( constint a[], int n )
{
int max = a[0];
for ( int i = 1; i < n; i++ )
{
if ( max < a[i] ) max = a[i];
}
return ( max );
}
int FindMin( constint a[], int n )
{
int min = a[0];
for ( int i = 1; i < n; i++ )
{
if ( a[i] < min ) min = a[i];
}
return ( min );
}