double mean(const double* scores, int numScores)
{
const double* ptr = scores;
double tot = 0;
while (ptr != scores + numScores)
{
tot += *ptr;
ptr++;
}
return tot/numScores;
}
#include<iostream>
using namespace std;
double mean(const double* scores, int numScores)
{
double tot = 0;
for (int i = 0; i < numScores; i++)
{
tot += *(scores + i);
}
return tot / numScores;
}
int main()
{
const int N = 5;
const double scores[N] = { 1,3,6,8,10};
cout << mean(scores, N);
}
Comments
Leave a comment