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

📄 pr0719.cpp

📁 practice c++, it is from the book http://www.amazon.com/Schaums-Outline-Programming-John-Hubbard
💻 CPP
字号:
//  Programming with C++, Second Edition, by John R. Hubbard
//  Copyright McGraw-Hill, 2000
//  Problem 7.19 on page 176
//  Summing a function with return type double

#include <cmath>     // defines the sqrt() function
#include <iostream>  // defines the cout object
using namespace std;

double sum(double (*)(double), int);

int main()
{ for (int x=0; x<5; x++)
    cout << "    sqrt(" << x << ") = " << sqrt(x)
         << "\nsum(sqrt," << x << ") = " << sum(sqrt,x) << endl;
}

double sum(double (*pf)(double x), int n)
{ // returns the sum f(0) + f(1) + f(2) + . . . + f(n-1)
  // where f() = *pf():
  double sum = 0;
  for (int i = 1; i <= n; i++)
    sum += (*pf)(i);
  return sum;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -