Write a function called Average that takes in an array of ints and calculates and returns the average of those numbers.
1
Expert's answer
2013-02-20T10:34:28-0500
#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);
Comments
Leave a comment