求1+2+3+...+n c++
求1+2+3+...+n
http://www.nowcoder.com/questionTerminal/7a0da8fc483247ff8800059e12d7caf1
class Solution {
public:
int Sum_Solution(int n) {
n && (n += Sum_Solution(n - 1));//前面为假,后面就不算了。自动不成立了
return n;
}
};
求1+2+3+...+n
http://www.nowcoder.com/questionTerminal/7a0da8fc483247ff8800059e12d7caf1
class Solution {
public:
int Sum_Solution(int n) {
n && (n += Sum_Solution(n - 1));//前面为假,后面就不算了。自动不成立了
return n;
}
};
相关推荐