Answer to Question #24389 in C++ for Nourah

Question #24389
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);

getch();& &
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS