### Need help!!

I need to find the maximum and minimum values of an array usings function with there prototypes and i dont whats the deal.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263`` ``````#include #include using namespace std; void min_element(int array[], int val); //function prototypes void max_element(int array[], int val); int main(void) { int x = 0; int myarray[100]; int val = 0; int mymin, mymax; cout << "Enter the numbers of elements in the array: " << endl; cin >> x; if (x >= 100) { cout << "sorry. too large. 100 max. "<> val; myarray[i] = val; } mymin = min_element(myarray, x); mymax = max_element(myarray, x); cout << "The minimum element of the array is " << mymin << endl; cout << "The maximum element of the array is " << mymax << endl; #ifdef WIN32 system("pause"); #endif return 0; } void min_element(int array[], int val); //functions void max_element(int array[], int val); { for (i = 0; i < val; i++) { if (array[i] < min ) { min = array[i]; } else if (array[i] > max ) { max = array[i]; } }``````
Last edited on
put the code inside [code] tag to make it readable
alright im new to this but its readable now codder101
 ``1234567`` ``````// void min_element(int array[], int val); // return the largest element // const int array[]. const - we do not need to modify it // sz == size of the array (number of elements in it) // assumes that sz is positive (greater than zero) int max_element( const int array[], int sz ) ; // declaration ``````

 ``123456789101112131415161718`` ``````int max_element( const int array[], int sz ) // definition { // initially, let the max element be the element right at the beginning int largest_so_for = array[0] ; // for every element starting at position one up to the end for( int i = 1 ; i < sz ; ++i ) { if( array[i] > largest_so_for ) // if it is larger than the largest so far largest_so_for = array[i] ; // it becomes the largest now } // we have gone through the entire array; // largest so far is the largest element in the array // return it so that the caller of the function will get it as the result return largest_so_for ; }``````

And likewise for `int min_element( const int array[], int sz )`

I wrote this
program for a girl
yesterday!

have some extra functions
but may help like an example:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788`` ``````//ProcessArrayData.cpp //# #include using std::cout; using std::cin; using std::endl; void printArray(const int a[],int size,const int NUM_PER_LINE); //function prototypes void setArray(int a[],int size); int getSumArray(const int a[],int size); int getSmallestArrayElement(const int a[],int size); int getHighestArrayElement(const int a[],int size); double getAverageArrayElements(const int a[],int size); int main(){ const int MAX=12; const int NUM_PER_LINE=6; int array[MAX]={}; //array elements initialized to 0 cout<<"Enter "<>array[index]; }//end for }//end function setArray int getSumArray(const int array[],int size){ int sum=0; for(int index=0;index(sum)/size; return average; }//end function getAverageArrayElements int getSmallestArrayElement(const int array[],int size){ int smallest=array[0]; for(int index=1;indexhighest) highest=array[index]; return highest; }//end function getLargestArrayElement ``````

 ``` Eyenrique-MacBook-Pro:Help Eyenrique\$ ./ProcessArrayData Enter 10 numbers Enter value #1:1 Enter value #2:2 Enter value #3:3 Enter value #4:4 Enter value #5:5 Enter value #6:6 Enter value #7:7 Enter value #8:8 Enter value #9:9 Enter value #10:10 Array elements are: 1 2 3 4 5 6 7 8 9 10 Sum: 55 Average: 5.5 Highest: 10 Smallest: 1 ```

EDIT: was for a girl
Last edited on
Topic archived. No new replies allowed.