求 1+2+...+n, 要求不能使用乘除法、for、while、if、else、switch、case 等关键字以及条件判断语句 (A?B:C)。

求 1+2+...+n,
要求不能使用乘除法、for、while、if、else、switch、case 等关键字以及条件判断语句 (A?B:C)。

#include <bits/stdc++.h>

using namespace std;

int Sum(int n)
{
    int Ret = 0;
    n == 0 || (Ret = Sum(n-1));
    return n + Ret;
}

class A{
    public:
    A()
    {
        sum += ++n;
    }
    static int sum;
    static int n;
};
int A::sum = 0;
int A::n = 0;
int main()
{
    int ans = Sum(10);
    cout << ans << endl;
    A a[10];
    cout << A::sum << endl;
 } 
原文地址:https://www.cnblogs.com/yifi/p/6707116.html