Question

c++ please 1. Write and test the function maximum that is passed an array of n...

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);

Homework Answers

Answer #1

#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
c++ please 1. Write and test the function maximum that is passed an array of n...
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. The function has the following prototype. int maximum ( int *p [ ], int n);
Write a function that accepts an int array and the array’s size as arguments. The function...
Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named data into an...
Write a function that accepts an int array and the array’s size as arguments. The function...
Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N...
Write a function that passes an array argument, getRandomNumbers, to get a pointer to an array...
Write a function that passes an array argument, getRandomNumbers, to get a pointer to an array of random numbers in the array. The function dynamically allocates an array, uses the system clock to seed the random number generator, populates the array with random values, and then returns a pointer to the array. Function getRandomNumbers to generate a random array and return a pointer. int* getRandomNumbers(int num); // The parameter indicates the number of numbers requested. The algorithm can be described...
Question 5: Recommend / Explain a C++ program which uses an array of 20 integers whose...
Question 5: Recommend / Explain a C++ program which uses an array of 20 integers whose input is taken by user, the array is passed to a functions named i.e. smallest(int A[20) and largest(int B[20]) to determine minimum and maximum values respectively. Also create a function named modify(int *p) which modifies the value at the index given by user.
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two different classes in the program being made as objects in the main (Bunny class and Dog Class). ask the user "what kind of animal would you like to sort?" user chooses the type of animal (bunny or dog), then you ask the user how big would you like the array of animals to be (maximum array size = 20)? and then you ask what...
Write a c++ function which takes two parameters: an array of ints and an int size...
Write a c++ function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void printSome(const int array[], int size);
Write a sum function in C++ for LinkedBag of integers (must use pointers to traverse the...
Write a sum function in C++ for LinkedBag of integers (must use pointers to traverse the linked list) that will return a sum of all values.
Write a function called read floats(int n) that reads n float values from the user into...
Write a function called read floats(int n) that reads n float values from the user into an array and return the array back to the caller. Recall that a regular array will get deallocated when the function returns. (C++ the simplier the better)