ex5_05.cpp
来自「Beginning Visual C++ 6源码。Wrox。」· C++ 代码 · 共 29 行
CPP
29 行
// EX5_05.CPP
// Handling an array in a function as a pointer
#include <iostream>
using namespace std;
double average(double* array, int count); //Function prototype
int main(void)
{
double values[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };
cout << endl
<< "Average = "
<< average(values, (sizeof values)/(sizeof values[0]));
cout << endl;
return 0;
}
// Function to compute an average
double average(double* array, int count)
{
double sum = 0.0; // Accumulate total in here
for(int i = 0; i<count; i++)
sum += *array++; // Sum array elements
return sum/count; // Return average
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?