题目描述

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

分析:可以使用递归!

class Solution {
public:
    int Sum_Solution(int n) {
        int sum=n;
    (n>0)&&(sum+=Sum_Solution(n-1));
    return sum;
    }
};

相关文章:

  • 2021-10-22
  • 2022-01-17
  • 2021-06-18
  • 2022-12-23
  • 2021-05-27
  • 2022-03-08
  • 2021-08-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2021-06-13
  • 2021-06-22
  • 2021-08-21
  • 2022-12-23
  • 2021-11-26
相关资源
相似解决方案