第12题
题目:求1+2+…+n,
要求不能使用乘除法、for、while、if、else、switch、case等关键字
以及条件判断语句(A?B:C)
#include<iostream>
using namespace std;
class tmp
{
public:
tmp()
{
n++;
m += n;
}
static int getsum()
{
return m;
}
private:
static int n;
static int m;
};
int tmp::m = 0;
int tmp::n = 0;
int main()
{
int x;
cin >> x;
tmp *ptr = new tmp[x];
delete[]ptr;
cout << ptr->getsum() << endl;
system("pause");
}