|
-
July 15th, 2011, 01:49 PM
#1
Max and Min using arrays and pointers
I'm new in C++, and I have been trying to come with a code to get the max and min value of and array. The program prompt the user to enter a series of integers. I also using pointers.
Here is my code
#include<iostream>
#include<string>
using namespace std;
int minimun( const int* values, size_t numValues);
int maximum( const int* values, size_t numValues);
int main()
{
const size_t maxValues = 10;
const int array7Size = 10;
int array7[array7Size] = {};
int *array7Ptr = array7;
int array7min = array7[0];
int array7max = array7[0];
cout <<" Enter up to 10 integers"<< endl;
minimun( array7, array7min );
maximum( array7, array7max );
cout <<"Minimum value: "<< array7min << endl;
cout <<"Maximum value: "<< array7max << endl;
} // end while
//fFunctions that find the maximum value of the array.
int maximun( const int* array7 [], size_t array7max )
{
for ( size_t i = 0; i < array7max ; i++ )
{
cin >> *array7max[i];
if ( *array7[i] > array7max )
{
array7max = array7max[i];
}
}
return array7max;
}
// function that find the minimum value nof the array.
int miminum(const int* array7 [], size_t array7min)
{
if (*array7[i] < array7min )
{
array7min = *(array7min + i);
}
return array7min;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|