c++ please
1. Write and test the function maximum that is passed an array of n pointers to integers and returns the maximum value among the n integers. The function must use the traveling pointer notation to traverse the array. you have to ask the user for the size of the array and ask the user to input the values in the main. The function has the following prototype.
int maximum ( int *p [ ], int n);
#include <iostream>
using namespace std;
int maximum ( int *p[], int n)
{
int max=0,i;
for(i=0;i<n;i++)
{
if(max<*p[i])//checking the value in that address with
maximum
{
max=*p[i];
}
}
return max;
}
int main()
{
int a[15];
int *b[15],i,n;
cout<<"enter n value"<<endl;
cin>>n;
cout<<"enter value into array"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<5;i++)
{
b[i]=&a[i];//assigning each int value address to pointer
array
}
cout<<maximum(b,5);
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.