Arrays

closed account (G60iz8AR)
Does anyone know how to start out/finish the code below using arrays ? If so, please help !
#include <iostream>
#include <string>

using namespace std;

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: " << maxVal( 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
}
You iterate through your array with a for loop. In fact, there was a thread here already about this exact same problem. You should at least attempt the print function first, and the rest will follow quite easily from there.
Topic archived. No new replies allowed.