码迷,mamicode.com
首页 > 其他好文 > 详细

[剑指offer] 47. 求1+2+3+...+n

时间:2018-12-25 11:29:18      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:div   describe   判断语句   条件判断语句   要求   ase   color   for   class   

题目描述

求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
class Solution
{
  public:
    int Sum_Solution(int n)
    {
        if (n == 0)
            return 0;
        return n + Sum_Solution(n - 1);
    }
};

 

[剑指offer] 47. 求1+2+3+...+n

标签:div   describe   判断语句   条件判断语句   要求   ase   color   for   class   

原文地址:https://www.cnblogs.com/ruoh3kou/p/10172487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!