/*
求1+2+…+n
要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A ? B : C)。
//*/
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
class nplus{
public:
static int cnt;
static int sum;
static unsigned long plus;
nplus(){++cnt; sum += cnt;plus *= cnt;}
~nplus(){}
};
int nplus::cnt = 0;
int nplus::sum = 0;
unsigned long nplus::plus = 1;
int main()
{
nplus np[10];
cout << "sum: " << nplus::sum << " plus: " << nplus::plus << endl;
return 0;
}
求1+2+…+n 要求不能使用乘除法
最新推荐文章于 2021-02-20 15:25:07 发布