void printArr( int a[], int cnt );
int sumArr( int a[], int cnt );
double aveArr( int a[], int cnt );
int minVal( int a[], int cnt );
int maxVal( int a[], int cnt );
int main ()
{
int arr[10];
int count;
for ( count=0 ; count<5 ; count++ )
arr[count] = count*2;
printArr( arr, count );
cout << " sum of all initialized elements in array is: " << sumArr( arr, count ) << endl;
cout << " ave of all initialized elements in array is: " << aveArr( arr, count ) << endl;
cout << " the smallest number in the array is: " << minVal( arr, count ) << endl;
cout << " the largest number in the array is: " << minVal( arr, count ) << endl;
return 0;
}
// print all the initilized values in the array from front to back
void printArr( int a[], int cnt )
{
// your code here
}
// return the sum of the initilized values in the array
int sumArr( int a[], int cnt )
{
// your code here
return 0; // just to make it compile - you change as needed
}
// return the ave of the initilized values in the array
double aveArr( int a[], int cnt )
{
// your code here
return 0; // just to make it compile - you change as needed
}
// return the smallest number in the array
int minVal( int a[], int cnt )
{
// your code here
return 0; // just to make it compile - you change as needed
}
// return the largest number in the array
int maxVal( int a[], int cnt )
{
// your code here
return 0; // just to make it compile - you change as needed
}
Min and max you would just have to loop through the array and compare whether they are less than or equal to the previous min/max..
I'll get you started with min
1 2 3 4 5 6 7 8 9 10 11 12 13
int min( constint *ARRAY , constint SIZE )
{
int min = 9; //start at the highest digit then compare
for( int i = 0; i < SIZE; ++i )
{
if( ARRAY[i] < min )
{
min = ARRAY[i];
}
}
return( min );
}
Another method you could do to get the min and max at the same time would be to use a bubble sort method on your array and say put it in ascending order. Then when you call your min/max functions the min will return the first element and the max will return the last element.