⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex5_05.cpp

📁 Visual C++ 2005的源代码
💻 CPP
字号:
// Ex5_05.cpp
// Handling an array in a function as a pointer
#include <iostream>
using std::cout;
using std::endl;

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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -