Question #24389

Write a function called Average that takes in an array of ints and calculates and returns the average of those numbers.

Expert's answer

#include <iostream>
using namespace std;

#include <conio.h>

double average(int* array, int size)
{
int val = 0;
for(i = 0;i < size; i++ )
{
val = val + *array[i];
}
double av = val/size;
return size;
}

int main()
{
int size;
cout << "Input size of array: ";
cin >> size;
int* array = new int[size];
cout << "Input the integer numbers";
for(int i = 0; i < size;i++)
{
& cout << "array["<<i+1<<"]: ";
& cin >> *array[i];
}
cout << endl<< "The average value is: "<<average(array,size);

getch();& &
}
LATEST TUTORIALS
APPROVED BY CLIENTS