#include <iostream>
using namespace std;
int f1(int n)
{
return 0;
}
int f2(int n)
{
static int (*f[2])(int) = {f1,f2};
return f[!!n](n - 1) + n;
}
int main()
{
int n;
cout << "输入n的值<<endl";
cin >> n;
int sum = f2(n);
cout << "sum=" << sum << endl;
return 0;
}
求1+2+3+...+n的值(用函数指针数组实现)
最新推荐文章于 2023-12-12 23:26:31 发布